xsl-list
[Top] [All Lists]

Re: [xsl] Find the node with maximum elements

2007-11-05 11:02:42
Nice solution, Scott.

On 11/5/07, Scott Trenda <Scott(_dot_)Trenda(_at_)oati(_dot_)net> wrote:
This may be better represented with 2.0's grouping facilities, but
here's the 1.0 solution I'd use to alleviate Mukul's concerns (building
off Michael's response with <xsl:sort/>):

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

 <xsl:key name="cars" match="*[Car]" use="count(Car)"/>

 <xsl:template match="Sample">

   <xsl:variable name="max-cars">
     <xsl:for-each select=".//*[Car]">
       <xsl:sort select="count(Car)" data-type="number"/>
       <xsl:if test="position() = last()">
         <xsl:value-of select="count(Car)"/>
       </xsl:if>
     </xsl:for-each>
   </xsl:variable>

   <xsl:for-each select="key('cars', $max-cars)">
     <!-- do whatever you'd do with the results here -->
     <xsl:value-of select="name()"/>
   </xsl:for-each>

 </xsl:template>

</xsl:stylesheet>

~ Scott


-- 
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>