XSLT根据条件拆分XML文件
首先,我没有足够的xslt经验。我需要基于InoviceNo将XML拆分为2个文件的帮助。如果InvoiceNo=“+”将其包含在前面的同级中,其中InvoiceNo等于一个数字 源文件XSLT根据条件拆分XML文件,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,首先,我没有足够的xslt经验。我需要基于InoviceNo将XML拆分为2个文件的帮助。如果InvoiceNo=“+”将其包含在前面的同级中,其中InvoiceNo等于一个数字 源文件 <?xml version="1.0"?> <ns:MT_CheckoutReport xmlns:ns="http://test.com/LE/ChannelAdvisor"> <row> <row>
<?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>
547194
8/02/2021 19:29
159.99
亚马逊
0/0
547195
8/02/2021 19:29
219.98
亚马逊
0/0
+
期望输出。
文件1
547194
8/02/2021 19:29
159.99
亚马逊
0/0
文件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>
547195
8/02/2021 19:29
219.98
亚马逊
0/0
+
我的尝试
<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>
为什么不简单地:
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>
为什么不简单地:
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>