This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
counting/comparing values
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] counting/comparing values
- From: "Dunning, John" <JDunning at goSPS dot com>
- Date: Fri, 9 Nov 2001 13:53:00 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Greetings all,
I am stuck trying to get the highest number of child elements of a
particular type. What I would like to do is return the count of the most
<entry> elements within a single <row> of a <table>:
<table>
<tbody>
<row>
<entry>1</entry>
</row>
<row>
<entry>1</entry>
<entry>2</entry>
</row>
<row>
<entry>1</entry>
<entry>2</entry>
<entry>3</entry>
</row>
</tbody>
</table>
The template processing this is:
<xsl:template match="table">
<table>
<xsl:variable name="col_count">
<xsl:for-each select="child::tbody[1]/row">
<xsl:choose>
<xsl:when test="count(preceding-sibling::row/child::entry)
> count(entry)">
<xsl:value-of
select="count(preceding-sibling::row/child::entry)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(entry)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:attribute name="col_count"><xsl:value-of
select="$col_count"/></xsl:attribute>
</table>
</xsl:template>
Which returns:
<table col_count="123"/>
When what I want is <table col_count="3"/>
Any ideas? Any and all help appreciated.
Thanks, John
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list