首先,我对xslt没有足够的经验。我需要帮助将XML拆分成两个基于InoviceNo的文件。如果InvoiceNo = "+“,则将其包含在前面的兄弟姐妹中,其中InvoiceNo等于一个数字。
源文件
<?xml version="1.0"?>
<ns:MT_CheckoutReport xmlns:ns="http://test.com/LE/ChannelAdvisor">
<row>
<row>
<InvoiceNo>547194</InvoiceNo>
<CheckoutDate>8/02/2021 19:29</CheckoutDate>
<TotalInvoiceAmt>159.99</TotalInvoiceAmt>
<PymtType>Amazon</PymtType>
<PymtID></PymtID>
<PymtExp>0/0</PymtExp>
<CVV></CVV>
</row>
</row>
<row>
<row>
<InvoiceNo>547195</InvoiceNo>
<CheckoutDate>8/02/2021 19:29</CheckoutDate>
<TotalInvoiceAmt>219.98</TotalInvoiceAmt>
<PymtType>Amazon</PymtType>
<PymtID></PymtID>
<PymtExp>0/0</PymtExp>
<CVV></CVV>
</row>
</row>
<row>
<row>
<InvoiceNo>+</InvoiceNo>
<CheckoutDate></CheckoutDate>
<TotalInvoiceAmt></TotalInvoiceAmt>
<PymtType></PymtType>
<PymtID></PymtID>
<PymtExp></PymtExp>
<CVV></CVV>
</row>
</row>
</ns:MT_CheckoutReport>期望输出档案1
<?xml version="1.0"?>
<ns:MT_CheckoutReport xmlns:ns="http://test.com/LE/ChannelAdvisor">
<row>
<row>
<InvoiceNo>547194</InvoiceNo>
<CheckoutDate>8/02/2021 19:29</CheckoutDate>
<TotalInvoiceAmt>159.99</TotalInvoiceAmt>
<PymtType>Amazon</PymtType>
<PymtID></PymtID>
<PymtExp>0/0</PymtExp>
<CVV></CVV>
</row>
</row>文件2. InvoiceNo =+将其包含在InvoiceNo = 547195的兄弟姐妹的文件中。
<?xml version="1.0"?>
<ns:MT_CheckoutReport xmlns:ns="http://test.com/LE/ChannelAdvisor">
<row>
<row>
<InvoiceNo>547195</InvoiceNo>
<CheckoutDate>8/02/2021 19:29</CheckoutDate>
<TotalInvoiceAmt>219.98</TotalInvoiceAmt>
<PymtType>Amazon</PymtType>
<PymtID></PymtID>
<PymtExp>0/0</PymtExp>
<CVV></CVV>
</row>
</row>
<row>
<row>
<InvoiceNo>+</InvoiceNo>
<CheckoutDate></CheckoutDate>
<TotalInvoiceAmt></TotalInvoiceAmt>
<PymtType></PymtType>
<PymtID></PymtID>
<PymtExp></PymtExp>
<CVV></CVV>
</row>
</row>我的尝试
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="row">
<xsl:for-each-group select="row/InvoiceNo" group-by="InvoiceNo">
<xsl:result-document href="file_{current-grouping-key()}.xml">
<some>
<xsl:copy-of select="current-group()"/>
</some>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet> 发布于 2021-05-28 04:42:45
为什么不简单地:
XSLT2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://test.com/LE/ChannelAdvisor">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/ns:MT_CheckoutReport">
<xsl:for-each-group select="row" group-starting-with="row[row/InvoiceNo!='+']">
<xsl:result-document href="file_{row/InvoiceNo}.xml">
<ns:MT_CheckoutReport>
<xsl:copy-of select="current-group()"/>
</ns:MT_CheckoutReport>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/67731938
复制相似问题