我正在尝试使用这里使用的一些相同的逻辑https://stackoverflow.com/a/10629806/662877
到不同的 XML,但没有得到预期的输出。
如果 //TERR="KHM6" 则从输入中删除/剥离这 2 个元素 CreatePaymentItems和CreatePayExt并生成输出。有人可以告诉我我在这里缺少什么。
谢谢
XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"*[../TERR='KHM6']/CreatePaymentItems | *[../TERR='KHM6']/CreatePayExt"/>
</xsl:stylesheet>
示例输入 XML:
<ns0:DocTran doctype="Return" xmlns:ns0="http://test.Schemas.Out_Return">
<TransactionType>
<PayLineItems>
<PayLineInsert>
<PAYTYPE>4</PAYTYPE>
<NUMBER>R2293416</NUMBER>
<SERIAL>3335889530</SERIAL>
<DOCDATE>05/03/2012</DOCDATE>
<ITEMNMBR>4NZ3330000010</ITEMNMBR>
<UNITPRCE>599.99</UNITPRCE>
<XTNDPRCE>599.99</XTNDPRCE>
<QUANTITY>1</QUANTITY>
<TAXAMNT>43.65</TAXAMNT>
<QTYONHND>1</QTYONHND>
<TERR>KHM6</TERR>
</PayLineInsert>
</PayLineItems>
<PayLineEXT>
<PAYTYPE>4</PAYTYPE>
<NUMBER>R2293416</NUMBER>
<LNITMSEQ>2293416</LNITMSEQ>
</PayLineEXT>
<CreatePaymentItems>
<CreatePaymentInsertRecord>
<INTERID>TOTM</INTERID>
<PAYTYPE>4</PAYTYPE>
<PAYNUMBER>R2293416</PAYNUMBER>
<DOCDATE>05/03/2012</DOCDATE>
<DOCAMOUNT>645.03</DOCAMOUNT>
<DOCNUMBER>2293416</DOCNUMBER>
</CreatePaymentInsertRecord>
</CreatePaymentItems>
<CreatePayExt>
<PAYTYPE>4</PAYTYPE>
<PAYNUMBER>R2293416</PAYNUMBER>
<SEQNUMBR>61261585</SEQNUMBR>
</CreatePayExt>
</TransactionType>
</ns0:DocTran>
预期输出 XML:
<ns0:DocTran doctype="Return" xmlns:ns0="http://test.Schemas.Out_Return">
<TransactionType>
<PayLineItems>
<PayLineInsert>
<PAYTYPE>4</PAYTYPE>
<NUMBER>R2293416</NUMBER>
<SERIAL>3335889530</SERIAL>
<DOCDATE>05/03/2012</DOCDATE>
<ITEMNMBR>4NZ3330000010</ITEMNMBR>
<UNITPRCE>599.99</UNITPRCE>
<XTNDPRCE>599.99</XTNDPRCE>
<QUANTITY>1</QUANTITY>
<TAXAMNT>43.65</TAXAMNT>
<QTYONHND>1</QTYONHND>
<TERR>KHM6</TERR>
</PayLineInsert>
</PayLineItems>
<PayLineEXT>
<PAYTYPE>4</PAYTYPE>
<NUMBER>R2293416</NUMBER>
<LNITMSEQ>2293416</LNITMSEQ>
</PayLineEXT>
</TransactionType>
</ns0:DocTran>