我有匹配的問題。
我想要像下面這樣。
%3,00 CCC
%5,00 AAA
%3,00 CCC
%2,00 BBB
我得到了幫助并寫了一些東西,但如果超過 1 則在下面出現錯誤invoiceline。
致命錯誤:不允許將多個專案的序列作為 substring-after() 的第一個引數(“11_003_AAA”,“21_003_AAA”,...)不允許將多個專案的序列作為第一個引數substring-after() ("11_003_AAA", "21_003_AAA", ...)"
XML
<invoiceLine>
<ID>000011</ID>
<Note>40.00 BT</Note>
<Note>17_ 2005.00</Note>
<Note>11_005_AAA</Note>
<Note>11_002_BBB</Note>
<Note>11_003_CCC</Note>
<AllowanceCharge>
<MultiplierFactorNumeric>0.03</MultiplierFactorNumeric>
<Amount currencyID="USD">6.00</Amount>
</AllowanceCharge>
<AllowanceCharge>
<MultiplierFactorNumeric>0.05</MultiplierFactorNumeric>
</AllowanceCharge>
</invoiceLine>
<invoiceLine>
<ID>000021</ID>
<Note>10.00 CS</Note>
<Note>17_ 1005.00</Note>
<Note>21_005_AAA</Note>
<Note>21_002_BBB</Note>
<Note>21_003_CCC</Note>
<AllowanceCharge>
<MultiplierFactorNumeric>0.03</MultiplierFactorNumeric>
</AllowanceCharge>
<AllowanceCharge>
<MultiplierFactorNumeric>0.02</MultiplierFactorNumeric>
</AllowanceCharge>
</invoiceLine>
XSLT
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="2.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="note" match="./Note" use="substring-before(substring-after(., '_'), '_')" />
<xsl:template match="/invoiceline">
<xsl:for-each select="./AllowanceCharge/MultiplierFactorNumeric">
<xsl:text> %</xsl:text>
<xsl:value-of select="format-number(. * 100, '###.##0,00', 'european')"/>,
<xsl:value-of select="substring-after(substring-after(key('note', format-number(100 * ., '000')), '_'), '_')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
uj5u.com熱心網友回復:
首先,您的輸入不是格式良好的 XML 檔案。您必須有一個根元素 - 例如:
XML
<invoiceLines>
<invoiceLine>
<ID>000011</ID>
<Note>40.00 BT</Note>
<Note>17_ 2005.00</Note>
<Note>11_005_AAA</Note>
<Note>11_002_BBB</Note>
<Note>11_003_CCC</Note>
<AllowanceCharge>
<MultiplierFactorNumeric>0.03</MultiplierFactorNumeric>
<Amount currencyID="USD">6.00</Amount>
</AllowanceCharge>
<AllowanceCharge>
<MultiplierFactorNumeric>0.05</MultiplierFactorNumeric>
</AllowanceCharge>
</invoiceLine>
<invoiceLine>
<ID>000021</ID>
<Note>10.00 CS</Note>
<Note>17_ 1005.00</Note>
<Note>21_005_AAA</Note>
<Note>21_002_BBB</Note>
<Note>21_003_CCC</Note>
<AllowanceCharge>
<MultiplierFactorNumeric>0.03</MultiplierFactorNumeric>
</AllowanceCharge>
<AllowanceCharge>
<MultiplierFactorNumeric>0.02</MultiplierFactorNumeric>
</AllowanceCharge>
</invoiceLine>
</invoiceLines>
現在,如果您希望密鑰僅在 current 中作業invoiceLine,則必須以某種方式對其進行限制。如果您能夠使用 XSLT 2.0,那么您可以這樣做:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="note" match="Note" use="tokenize(., '_')[2]" />
<xsl:decimal-format name="european" decimal-separator="," grouping-separator="."/>
<xsl:template match="/invoiceLines">
<xsl:for-each select="invoiceLine">
<xsl:for-each select="AllowanceCharge">
<xsl:variable name="factor" select="100 * MultiplierFactorNumeric" />
<xsl:text> %</xsl:text>
<xsl:value-of select="format-number($factor, '#.##0,00', 'european')"/>
<xsl:text> </xsl:text>
<xsl:value-of select="tokenize(key('note', format-number($factor, '000'), ..), '_')[3]"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
要得到:
結果
%3,00 CCC
%5,00 AAA
%3,00 CCC
%2,00 BBB
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493456.html
