Re: [xsl] selecting nodes based on sibling values

Subject: Re: [xsl] selecting nodes based on sibling values
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 23 Nov 2010 16:22:00 +0100
Fabien Tillier wrote:

What could be the XPath expression to get the maximum number of nodes of
level=50 in data those keycode starts like the level=40 line ?
Here the answer would be 3 as the maximum number of level = 50 nodes for
a given level = 40 is 3

As you originally asked for an XPath expression here is a more compact form of the previous suggestion:


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

  <xsl:param name="l1" select="'50'"/>
  <xsl:param name="l2" select="'40'"/>

<xsl:key name="k1" match="row" use="level"/>

<xsl:template match="/">
<xsl:value-of
select="max(
for $group in key('k1', $l2)
return count(key('k1', $l1)[starts-with(keycode, $group/keycode)])
)"/>
</xsl:template>


</xsl:stylesheet>


--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread