[Home] [By Thread] [By Date] [Recent Entries]
Bhaskar wrote:
Hi, Cut n paste error? This is not XML and I don't see any levels in it. I am basically trying to get the sum of third-level deep elements categorized by their names. That is, the output will be: you can get the name of an element using name() or local-name(). you can find the depth of an element using count(ancestor-or-self::*). So, suppose you have any input (provided it is XML) and it has some hierarchy of nodes, I think you can do something like this, which will : <xsl:template match="/" name="main"> <xsl:for-each-group select="$data//*[count(ancestor-or-self::*) = 3]" group-by="local-name()" > <xsl:value-of select="local-name(), ' ', sum(current-group()), '(', (current-group()/(string(), '+'))[position() != last()], ')
'" /> </xsl:for-each-group> </xsl:template> where the core of the for-each is actually sum(current-group()). The rest is to make it nice strings. If you use the following input: <l1>
<l2>
<l3a>234</l3a>
<l3b>2755</l3b>
</l2>
<l2>
<l3c>32</l3c>
<l3b>76</l3b>
<l3b>5345</l3b>
<l3b>233</l3b>
<l3c>43</l3c>
</l2>
<l2>
<l3a>112</l3a>
<l3a>987</l3a>
</l2>
</l1>
HTH, Cheers, -- Abel Braaksma
|

Cart



