私はXSLTに問題があります。ノードの合計をパラメータで計算するのが好きです。XSLTパラメータのノード数の合計
XMLソースは次のようになります。
<Documents>
<Document>
<Deleted>0</Deleted>
<DocumentType>2</DocumentType>
<Currency>EUR</Currency>
<CurrencyRate>4.368400</CurrencyRate>
<GrossValue>1000.00</GrossValue>
<DeliveryDate>2016-08-01</DeliveryDate>
<FormOfPayment>2</FormOfPayment>
<DueDate>2016-09-28</DueDate>
</Document>
<Document>
<Deleted>0</Deleted>
<DocumentType>2</DocumentType>
<Currency>EUR</Currency>
<CurrencyRate>4.368400</CurrencyRate>
<GrossValue>2000.00</GrossValue>
<DeliveryDate>2016-08-05</DeliveryDate>
<FormOfPayment>5</FormOfPayment>
<DueDate>2016-09-05</DueDate>
</Document>
<Document>
<Deleted>0</Deleted>
<DocumentType>2</DocumentType>
<Currency>EUR</Currency>
<CurrencyRate>4.368400</CurrencyRate>
<GrossValue>3000.00</GrossValue>
<DeliveryDate>2016-08-30</DeliveryDate>
<FormOfPayment>2</FormOfPayment>
<DueDate>2016-10-29</DueDate>
</Document>
<Document>
<Deleted>0</Deleted>
<DocumentType>2</DocumentType>
<Currency>EUR</Currency>
<CurrencyRate>4.368400</CurrencyRate>
<GrossValue>2500.00</GrossValue>
<DeliveryDate>2016-08-26</DeliveryDate>
<FormOfPayment>5</FormOfPayment>
<DueDate>2016-09-10</DueDate>
</Document>
</Documents>
私は必要な結果をパラメータFormOfPayment
によってGrossValue額の合計です。
- ので
FormOfPayment
が5であれば、変数GrossValueCard
は4500 - する必要があり、
FormOfPayment
が2であるとき、変数GrossValueCash
は4000
である必要があり、私はそのようにこれを実行しようとした。
<xsl:template name="Suma">
<xsl:param name="index" select="1"/>
<xsl:param name="nodes"/>
<xsl:param name="totalAmount" select="0"/>
<xsl:variable name="currentAmount" select="translate($nodes[$index],',','.')"/>
<xsl:choose>
<xsl:when test="count($nodes)=0">
<xsl:value-of select="0"/>
</xsl:when>
<xsl:when test="$index=count($nodes)">
<xsl:value-of select="$totalAmount + $currentAmount"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Suma">
<xsl:with-param name="index" select="$index+1"/>
<xsl:with-param name="totalAmount" select="$totalAmount + $currentAmount"/>
<xsl:with-param name="nodes" select="$nodes"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
となりますが、合計はすべてGrossValue
ノードです。 FormOfPayment
で合計を選択するためのパラメータを設定する必要があるというアドバイスを教えてください。
"when"または "if"の条件でこれを選択しようとしましたが、動作しませんでした。
あなたは 'GrossValueCard'のためのあなたの望ましい結果の数式を提供することができます? – zx485
結果GrossValueCardは、FormOfPayment5を持つドキュメントのGrossValueノードをすべて合計したものです.Xsltはすべてのドキュメントを調べ、GrossValueをGrossValueCardという名前の変数に集計します。 – jeffers