在以下 XML 中:
<?xml version="1.0" encoding="utf8" ?>
<Output>
<Error>
<Status>0</Status>
<Details>No errors</Details>
</Error>
<Synopsis>
<Count>451</Count>
</Synopsis>
<BankAccounts>
<BankAccount AcctNo="103" CustName="Frank" BalanceAmount="" Inactive="N" NoOfAccounts="1" >
<Addresses>
<Address>ABC</Address>
<Address>XYZ</Address>
</Addresses>
</BankAccount>
<BankAccount AcctNo="101" CustName="Jane" BalanceAmount="10005" Inactive="N" NoOfAccounts="1" >
<Addresses>
<Address>LMN</Address>
<Address>QWE</Address>
</Addresses>
</BankAccount>
</BankAccounts>
</Output>
我想在概要之后和 BankAccounts 之前添加一條處理指令:
<?xml-multiple BankAccount
?>
嘗試使用以下 XSLT,但它在“BankAccounts”中插入 PI 如何使用 XSLT 執行此操作?
<xsl:template match="BankAccounts">
<xsl:copy>
<xsl:processing-instruction name="xml-multiple">
BankAccount
</xsl:processing-instruction>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
uj5u.com熱心網友回復:
如果您希望處理指令出現在之前BankAccounts,請在復制之前將其寫入輸出BankAccounts:
<xsl:template match="BankAccounts">
<xsl:processing-instruction name="xml-multiple">BankAccount</xsl:processing-instruction>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
在 XSLT 2.0 或更高版本中,您可以將其縮短為:
<xsl:template match="BankAccounts">
<xsl:processing-instruction name="xml-multiple">BankAccount</xsl:processing-instruction>
<xsl:next-match/>
</xsl:template>
(假設您有身份轉換模板或等效模板)。
或者 - 在任何版本中 - 你可以簡單地做:
<xsl:template match="BankAccounts">
<xsl:processing-instruction name="xml-multiple">BankAccount</xsl:processing-instruction>
<xsl:copy-of select="."/>
</xsl:template>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/466247.html
