Re: [xsl] Find the node with maximum elements

Subject: Re: [xsl] Find the node with maximum elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 03 Nov 2007 15:19:45 -0400
At 2007-11-03 12:05 -0700, Avaneesh Ramprasad wrote:
I have a requirement to write a xsl transformation to find the node which has the maximum number of elements
The xsl should return Honda and Mitsubishi

Not sure where you are having the problem, but XSLT 2 provides the max() function that makes this very easy.

I hope the solution below helps. You can optimize the speed by putting the max value into a variable and testing against that, but I just wrote the XPath as I said the requirement aloud, so this is what I ended up with.

. . . . . . Ken

T:\ftemp>type avaneesh.xml

T:\ftemp>type avaneesh.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each select="/Sample/*[count(Car)=max(/Sample/*/count(Car))]">
    <xsl:value-of select="name(.)"/>

T:\ftemp>xslt2 avaneesh.xml avaneesh.xsl con


Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread