[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: counting/comparing values

Subject: Re: counting/comparing values
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Sat, 10 Nov 2001 04:44:19 +0100
comparing values in xsl
Hi John,

the easiest and most obviously version is to sort all rows by the count of
there entries.

<xsl:template match="tbody">
    <table>
        <xsl:attribute name="col_count">
            <xsl:for-each select="row">
                <xsl:sort select="count(entry)" order="descending"/>
                <xsl:if test="position() = 1">
                    <xsl:value-of select="count(entry)"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:attribute>
    </table>
</xsl:template>

But there are a few generic versions of better algorithms. Search for
'generic' and 'Dimitre' in the archives and you will find few answers I
think.

Hope this helps,

Joerg

> 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)
> &gt; 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.