特定のノード値に基づいて xml をグループ化しようとしています。
<bus:TaxList>
<bus:VoPaidTax>
<bus:TaxAmount>4.45</bus:TaxAmount>
<bus:TaxCode>10</bus:TaxCode>
<bus:TaxRate>0.05</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
<bus:VoPaidTax>
<bus:TaxAmount>6.23</bus:TaxAmount>
<bus:TaxCode>12</bus:TaxCode>
<bus:TaxRate>0.07</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
<bus:VoPaidTax>
<bus:TaxAmount>6.45</bus:TaxAmount>
<bus:TaxCode>10</bus:TaxCode>
<bus:TaxRate>0.05</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
<bus:VoPaidTax>
<bus:TaxAmount>9.03</bus:TaxAmount>
<bus:TaxCode>12</bus:TaxCode>
<bus:TaxRate>0.07</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
</bus:TaxList
次に、同じ TaxCode と Rate を持つ VoPaidTax グループを追加します。
<bus:TaxList>
<bus:VoPaidTax>
<bus:TaxAmount>10.90</bus:TaxAmount>
<bus:TaxCode>10</bus:TaxCode>
<bus:TaxRate>0.05</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
<bus:VoPaidTax>
<bus:TaxAmount>15.23</bus:TaxAmount>
<bus:TaxCode>12</bus:TaxCode>
<bus:TaxRate>0.07</bus:TaxRate>
<bus:TaxType>VAT</bus:TaxType>
</bus:VoPaidTax>
</bus:TaxList
そして、ユニークなものを残してください。
私はこのようなことを試しましたが、うまくいかないようですここで何が間違っていますか:
<xsl:template match="bus:TaxList">
<xsl:for-each select="bus:VoPaidTax[not(bus:TaxCode = ../preceding- sibling::*/bus:VoPaidTax/bus:TaxCode) and not(bus:TaxRate= ../preceding- sibling::*/bus:VoPaidTax/bus:TaxRate)]">
<xsl:call-template name="taxCorrection">
<xsl:with-param name="TaxCode">
<xsl:value-of select="bus:TaxCode"/>
</xsl:with-param>
<xsl:with-param name="percent">
<xsl:value-of select="bus:TaxRate"/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="taxCorrection">
<xsl:param name="TaxCode"/>
<xsl:param name="percent"/>
<xsl:variable name="sumTaxRate">
<xsl:value-of select="sum(../bus:VoPaidTax[bus:TaxCode = $TaxCode and bus:TaxRate =$percent]/bus:TaxAmount)" />
</xsl:variable>
</xsl:template>
問題は、このテンプレートが複数回呼び出され、合計と前の兄弟が機能していないように見えることです。ここで何が間違っていますか?? XSLT 1.0 を使用しています。誰か助けてください。