[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: General counting question: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|