2012-03-14 12 views
0

私は以下のXMLを持っています。xslt数字を追加するループ

<employee> 
    <record id=1> 
     <fname>mark</fname> 
     <lname>smith</lname> 
     <id>10</id> 
    <record id=2> 
    ........ 
</employee> 

各レコードにidを追加して合計を取得します。

私は従業員の下にあるレコードのexect番号を知らない。 1または10または100とすることができます。

私はこのフォーラムの1つの例から以下を見つけました。私はそれを使うことができますが、これを達成するための簡単な方法ですか?

<xsl:call-template name="for.loop"> 
<xsl:with-param name="i">1</xsl:with-param> 
<xsl:with-param name="count">10</xsl:with-param> 
</xsl:call-template> 
<!-- Rename "old name" elements to "new name" --> 
<xsl:template name="for.loop"> 
<xsl:param name="i"/> 
<xsl:param name="count"/> 
<xsl:if test="$i &lt;= $count"> 
<!-- body of the loop goes here --> 
</xsl:if> 
<xsl:if test="$i &lt;= $count"> 
    <xsl:call-template name="for.loop"> 
    <xsl:with-param name="i"> 
    <!-- Increment index--> 
    <xsl:value-of select="$i + 1"/> 
    </xsl:with-param> 
    <xsl:with-param name="count"> 
    <xsl:value-of select="$count"/> 
    </xsl:with-param> 
    </xsl:call-template> 
</xsl:if> 
</xsl:template> 
+1

あなたのデータは、整形式のXML(属性の周りに引用符なし)ではない、とあなたはid属性を合計するかどうか、それは明らかにされていないが、またはid要素。 –

答えて

1

sum機能があります:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/"> 
    <total> 
     <xsl:value-of select="sum(/employee/record/id)"/> 
    </total> 
    </xsl:template> 

</xsl:stylesheet> 
関連する問題