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

RE: selecting nodes based on sibling values

Subject: RE: selecting nodes based on sibling values
From: "Fabien Tillier" <f.tillier@xxxxxxxx>
Date: Tue, 23 Nov 2010 16:13:32 +0100
RE:  selecting nodes based on sibling values
Hi Martin
Clever....
Wish I could find it myself :)

Best regards,
Fabien



-----Message d'origine-----
De : Martin Honnen [mailto:Martin.Honnen@xxxxxx]
Envoyi : mardi 23 novembre 2010 16:09
@ : xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Objet : Re:  selecting nodes based on sibling values

Fabien Tillier wrote:

> <data>
> 	<row>
> 		<level>40</level>
> 		<keycode>1254.45.12</keycode>
> 	</row>
> 	<row>
> 		<level>50</level>
> 		<keycode>1254.45.12.7</keycode>
> 	</row>
> 	<row>
> 		<level>50</level>
> 		<keycode>1254.45.12.8</keycode>
> 	</row>
> 	<row>
> 		<level>50</level>
> 		<keycode>1254.45.12.9</keycode>
> 	</row>
>
> 	<row>
> 		<level>40</level>
> 		<keycode>99.25.6</keycode>
> 	</row>
> 	<row>
> 		<level>50</level>
> 		<keycode>99.25.6.45</keycode>
> 	</row>
> 	<row>
> 		<level>50</level>
> 		<keycode>99.25.6.46</keycode>
> 	</row>
> </data>
>
> 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

The following outputs "3" for your sample:

<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:variable name="groups" as="element(group)*">
       <xsl:for-each select="key('k1', $l2)">
         <group>
           <xsl:copy-of select="key('k1', $l1)[starts-with(keycode,
current()/keycode)]"/>
         </group>
       </xsl:for-each>
     </xsl:variable>
     <xsl:value-of select="max($groups/count(row))"/>
   </xsl:template>

</xsl:stylesheet>

--

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

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