Question

I have an XML file and part of the node tree is as the following... enter image description here

I have a template for the par node and within it I must sum the par elements between a range of holeNumbers, the following is part of my code but it isn't working at all and I'm not sure how to reference and sum the par elements based on the attribute values (the sum of the hole values 10-18 should be summed under the in column in the table below)...

<xsl:when test="@holeNumber = 18">
   <td class="sub"><xsl:value-of select="sum(.[@holeNumber > 9 and @holeNumber 
                                                             &lt; 18])" /></td>
   <td class="final"><xsl:value-of select="sum(//par)" /></td>
</xsl:when>

My table currently looks as the following...

hole |1 |2 |3 |4 |5 |6 |7 |8 |9 | out |10 |11 |12 |13 |14 |15 |16 |17 |18 | in
     |4 |4 |5 |3 |4 |4 |5 |3 |4 |     |4  |5  |4  |3  |4  |5  |4  |3  |4  |
Was it helpful?

Solution

Assuming <par> is the context node for this test, it seems seems you're running the sum() function on just this <par> element (I guess the result you're seeing is just the value of the currently selected <par> element?).

I think it's just a matter of selecting the right nodes for the sum() function, i.e. all <par> nodes:

<td class="sub"><xsl:value-of select="sum(//par[@holeNumber > 9 and @holeNumber 
                                                         &lt; 18])" /></td>

Still, this is more or less guesswork, since it would be much more informative if you just posted a relevant snippet of the XML source (instead of an image), and of the incorrect output. Would make your problem easier to grasp for golf-illiterates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top