I am new to XSL so I don´t really know how to do this. I have a for-each statement that does some computations for each element of a type "cell". How can I sum-up the results and store them in a variable so I can display it? I have included a part of the code.
I hope someone knows the solution to this problem. Thank you for your time and effort!
<?xml version="1.0"?>
<xsl:stylesheet version="1.0">
<xsl:output media-type="xml" encoding="ISO-8859-1" indent="yes"/>
<xsl:key name="object-map" match="/Data/Objects/*" use="@ExternalId"/>
<xsl:template match="/">
<Data>
<Objects>
...
...
...
<xsl:for-each select="Data/Objects/Cell">
<xsl:attribute name="PpXmlVer">
<xsl:text>7.0</xsl:text>
</xsl:attribute>
......................
<!--Calculating Machine Time: -->
<Cell>
<xsl:attribute name="ExternalId">
<xsl:value-of select="@ExternalId"/>
</xsl:attribute>
<!-- calculated.-->
<FlipMachineTime>
<xsl:choose>
<xsl:when test="./FlipPlanedOccupationTime > 0">
<xsl:value-of select="here is a complicated formula to compute"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</FlipMaschineTime>
</Cell>
</xsl:for-each>
Here I would like to have the sum of FlipMachineTime
for all encountered elements of type cell.
...........
</Objects>
</Data>
You should better use
exslt:node-set()
from http://exslt.org/common than the specific processor implementation being EXSLT much more portable on the various processors. In that case, you need:For example in Saxon 6.5 you should be able to use it like:
If you set the stylesheet version to 1.1, that's easier (as it should be):
After seeing your gist, I think you are working on something huge and complex which can not be solved here with a simple question. There can be too many details that you might have omitted. However if it's just the case of displaying a value (where???) I can suggest this last thing.
Try to create a variable for each cell:
You need to create a variable to hold the FlipMachineTime nodes you have computed. Then you can sum the nodeset. Here is some sample code:
To get this to work, make sure you include the xalan namespace in your stylesheet: