我有一些令人不安的問題,正在總結與每個元素有關的arraySize屬性數字。XSLT:以前所有屬性的總和
XML代碼:
<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代碼:這是怎麼了,我試圖解決這個問題。
<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>
預期輸出:
element #1
1
2
3
6
7
8
9
11
12
13
14
15
element #2
1
2
... etc
實際輸出:
1 <-- Problem #1
1
2
5
6
1 <--- Problem #2
2
4
5
6
7
15 <-- The correct summation is produced here.
我需要總結的所有preseding ARRAYSIZE的屬性。它有點作用,但是兩個問題是:1.第一個領域沒有總結。 2.總和重新開始於第三個縮進結構(如果縮進是正確的術語)。
有人可以幫助我嗎?
你能告訴你真正希望在這個輸出案件?謝謝! –
哦,對不起。忘了那個。我編輯了這篇文章。 –