xsl-list
[Top] [All Lists]

Re: [xsl] Find the node with maximum elements

2007-11-03 23:33:54
Hi Mike,
   IMHO, there seems to be a slight flaw in this logic. This program
will return only the last instance (i.e. only 1) of the maximum, and
not all maximum instances.

I think, Ken's answer meets exactly the OP's requirements.

On 11/4/07, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
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(_at_)rocketmail(_dot_)com]
Sent: 03 November 2007 19:05
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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


-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--