I am having some troubling getting summing up the arraySize attribute numbers pertaining to each element.
XML CODE:
<head>
<element>
<message name="something">
<field arraySize="1"/>
<struct name="asdf">
<struct name="qwera">
<field arraySize="1"/>
<field arraySize="1"/>
</struct>
<struct name="xcv">
<field arraySize="3"/>
<field arraySize="1"/>
</struct>
<struct name="nnge">
<struct name="sdfssk">
<field arraySize="1"/>
<field arraySize="1"/>
</struct>
<struct name="fhjmn">
<field arraySize="2"/>
<field arraySize="1"/>
</struct>
<struct name="wetryk">
<field arraySize="1"/>
<field arraySize="1"/>
</struct>
</struct>
</struct>
<field arraySize="1"/>
</message>
</element>
<element>
... similar struct "tree"
</element>
<element>
... similar struct "tree"
</element>
</head>
XSLT code: This is how I've tried to solve the problem.
<xsl:template match="p:struct">
<xsl:apply-templates>
<xsl:with-param name="previous" select="sum(preceding-sibling::*//@arraySize)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="p:field">
<xsl:param name="previous" select="0"/>
<xsl:value-of select="$previous + sum(preceding-sibling::*//@arraySize)"/>
</xsl:template>
Expected output:
element #1
1
2
3
6
7
8
9
11
12
13
14
15
element #2
1
2
... etc
Actual output:
1 <-- Problem #1
1
2
5
6
1 <--- Problem #2
2
4
5
6
7
15 <-- The correct summation is produced here.
I need to sum all of the preseding arraySize attributes. It works somewhat, but the two problems are: 1. the first field isn't summed. 2. The summation restarts at the third indented struct (if indented is the correct terminology).
Can someone help me?