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

RE: Find the node with maximum elements

Subject: RE: Find the node with maximum elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 3 Nov 2007 19:34:30 -0000
RE:  Find the node with maximum elements
Easiest (even in 2.0) is to sort elements according to the number of
children and take the last:

<xsl:for-each select="Sample/*">
  <xsl:sort select="count(child::*)" data-type="number"/>
  <xsl:if test="position()=last()">
    <xsl:value-of select="name()"/>
  </
</

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Avaneesh Ramprasad [mailto:avaneesh@xxxxxxxxxxxxxx] 
> Sent: 03 November 2007 19:05
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Find the node with maximum elements
> 
> Hello,
> I have a requirement to write a xsl transformation to find 
> the node which has the maximum number of elements
> 
> Below is a sample xml file 
> 
> <Sample>
>     <Toyota>
>           <Car>Camry</Car>
>           <Car>Corrola</Car>
>      </Toyota>
>      <Honda>
>             <Car>Accord></Car>
>           <Car>Civic</Car>
>           <Car>Pilot</Car>
>      </Honda>
>      <Mitsubishi>
>         <Car>Lancer</Car>
>         <Car>Lancer</Car>
>         <Car>Lancer</Car>
>      </Mitsubishi>
>     <Hyundai>
>         <Car>Sonata</Car>
>         <Car>Accent</Car>
> </Hyundai>
> </Sample>
> 
> The xsl should return Honda and Mitsubishi
> 
> Would appreciate your help.
> 
> Thanks
> Avaneesh

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-2011 All Rights Reserved.