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

Re: General counting question: finding max

Subject: Re: General counting question: finding max
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Aug 2000 19:51:25 +0100
finding max
Gert,

>I would like to find the length of the longest chain of <x>'s in the
>following document:
>
><a><x/<x/></a>
><a><x/></a>
><a><x/><x/><x/><x/></a>

One way that you could do this is to do a xsl:for-each on each of the 'a'
elements, sort them in order of the number of 'x' element children then
have (in descending order - biggest first), and then take the first one of
that list - that's the 'a' that you're interested in.  So:

<xsl:for-each select="a">
  <xsl:sort select="count(x)" order="descending" />
  <xsl:if test="position() = 1">
    <!-- this is the 'a' you were after -->
    Max number of 'x's = <xsl:value-of select="count(x)" />
  </xsl:if>
</xsl:for-each>

If this will work in your situation, I *think* it's the best method.  If it
won't, there are other ways of doing it, just about (I can think of two -
selecting the 'a' that does not have a sibling with more 'x' children, and
using keys - but I haven't tried them out).  Let me know if you want to see
them as well.

I hope this solution works for you,

Jeni

Jeni Tennison
http://www.jenitennison.com/


 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.