我需要根据"TaxRateCode;标签和基于";线型/代码="WT";并对";LineGrossMount/Value";每个OutboundPayment标签。
下方的XML
<?xml version="1.0" encoding="UTF-8"?>
<OutboundPaymentInstruction>
<OutboundPayment>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>CHANDLER BING</LineDescription>
<LineGrossAmount>
<Value>3098.76</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>CHANDLER BING</LineDescription>
<LineGrossAmount>
<Value>-1328.04</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>CHANDLER - INV2103-0185</LineDescription>
<LineGrossAmount>
<Value>44268</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
</OutboundPayment>
<OutboundPayment>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>TOT-760589905 checkin</LineDescription>
<LineGrossAmount>
<Value>2241.33</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT-760589905 checkin</LineDescription>
<LineGrossAmount>
<Value>-1525</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>5</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT-760589905 (21/12/2563 - 20/01/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>-45.57</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT-760589905 (21/12/2563 - 20/01/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>30500</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT-760589905 (21/12/2563 - 20/01/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>1519</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>TOT-763687229. ( 21/01/2564 - 20/02/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>2241.4</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT-763687229. ( 21/01/2564 - 20/02/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>-1525</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>5</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT-763687229. ( 21/01/2564 - 20/02/2564 ) Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>-45.6</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT-763687229. ( 21/01/2564 - 20/02/2564 )Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>30500</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT-763687229. ( 21/01/2564 - 20/02/2564 )Voice for outbound and inbound (Local Call) Link 2</LineDescription>
<LineGrossAmount>
<Value>1520</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>TOT- 763687230 Utilities</LineDescription>
<LineGrossAmount>
<Value>3193.33</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT- 763687230 Utilities</LineDescription>
<LineGrossAmount>
<Value>-2110</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>5</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT- 763687230 Utilities</LineDescription>
<LineGrossAmount>
<Value>-102.57</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT- 763687230 Utilities</LineDescription>
<LineGrossAmount>
<Value>42200</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT- 763687230 Utilities</LineDescription>
<LineGrossAmount>
<Value>3419</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955166 Utilities</LineDescription>
<LineGrossAmount>
<Value>1.81</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955166 Utilities</LineDescription>
<LineGrossAmount>
<Value>-1.29</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>4.998063</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955166 Utilities</LineDescription>
<LineGrossAmount>
<Value>25.81</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineType>
<Code>TAX</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955167 Utilities</LineDescription>
<LineGrossAmount>
<Value>1.81</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>AWT</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955167 Utilities</LineDescription>
<LineGrossAmount>
<Value>-1.29</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>4.998063</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineType>
<Code>ITEM</Code>
<Meaning />
</LineType>
<LineDescription>TOT 763955167 Utilities</LineDescription>
<LineGrossAmount>
<Value>25.81</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<Tax>
<TaxCode />
<TaxRate>0</TaxRate>
<TaxRateCode />
</Tax>
</DocumentPayableLine>
</DocumentPayable>
</OutboundPayment>
</OutboundPaymentInstruction>
预期输出
<TAX>
<Rcrd>
<TaxAmt>
<Rate>3</Rate>
<calc>1328.04</calc>
</TaxAmt>
</Rcrd>
</TAX>
<TAX>
<Rcrd>
<TaxAmt>
<Rate>5</Rate>
<calc>5162.58</calc>
</TaxAmt>
</Rcrd>
<Rcrd>
<TaxAmt>
<Rate>3</Rate>
<calc>193.74</calc>
</TaxAmt>
</Rcrd>
</TAX>
我已经尝试过下面的代码,但它没有给出预期的输出。它在使用";应付单据;标记在自己的";OutboundPayment";标签请帮助解决方案。还请注意,我们的需求只支持XSLT1.0版本,因此我使用了Muenchain分组方法。
代码尝试
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:key name="group1" match="DocumentPayable/DocumentPayableLine" use="concat(generate-id(..), Tax/TaxRateCode)"/>
<xsl:template match="/">
<xsl:for-each select="/OutboundPaymentInstruction/OutboundPayment">
<TAX>
<xsl:for-each select="DocumentPayable/DocumentPayableLine[count(. | key('group1', concat(generate-id(..), Tax/TaxRateCode))[1]) = 1]">
<xsl:if test="(LineType/Code='AWT')">
<xsl:variable name="LocationCode" select="Tax/TaxRateCode"/>
<Rcrd>
<TaxAmt>
<Rate>
<xsl:if test="not(Tax/TaxRate='')">
<xsl:value-of select="round(Tax/TaxRate)"/>
</xsl:if>
</Rate>
<xsl:variable name="calcualtedVal1">
<xsl:value-of select="translate(sum(//DocumentPayableLine[./Tax/TaxRateCode= $LocationCode]/LineGrossAmount/Value),'-','')"/>
</xsl:variable>
<calc>
<xsl:value-of select="$calcualtedVal1"/>
</calc>
</TaxAmt>
</Rcrd>
</xsl:if>
</xsl:for-each>
</TAX>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
AFAICT,它可以简单地为:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="k" match="DocumentPayableLine[LineType/Code='AWT']" use="concat(generate-id(../..), Tax/TaxRateCode)" />
<xsl:template match="/OutboundPaymentInstruction">
<xsl:for-each select="OutboundPayment">
<TAX>
<xsl:for-each select="DocumentPayable/DocumentPayableLine[LineType/Code='AWT'][count(. | key('k', concat(generate-id(../..), Tax/TaxRateCode))[1]) = 1]">
<Rcrd>
<TaxAmt>
<Rate>
<xsl:value-of select="Tax/TaxRate"/>
</Rate>
<calc>
<xsl:value-of select="-sum(key('k', concat(generate-id(../..), Tax/TaxRateCode))/LineGrossAmount/Value)"/>
</calc>
</TaxAmt>
</Rcrd>
</xsl:for-each>
</TAX>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
请注意,结果是XML片段,而不是格式良好的XML文档,因为它没有单个根元素。