我需要根据里面的标签拆分一个 XML 文件。这是输入文件的样子。spli 应该基于 Order 标签发生
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Root>
<MultiApi>
<API>
<Input>
<Order test="0001" >
<OrderLines>
<OrderLine test1="123" />
</OrderLines>
</Order>
<Order test="0002" >
<OrderLines>
<OrderLine test1="456" />
</OrderLines>
</Order>
<Order test="0003" >
<OrderLines>
<OrderLine test1="789" />
</OrderLines>
</Order>
</Input>
</API>
</MultiApi>
<MultiApi>
<EOF abc="test" MaxMsgPerFile="1" >
</EOF>
</MultiApi>
</Root>
输出应如下所示:
<Root>
<MultiApi>
<API>
<Input>
<Order test="0001" >
<OrderLines>
<OrderLine test1="123" />
</OrderLines>
</Order>
</Input>
</API>
</MultiApi>
<MultiApi>
<API>
<Input>
<Order test="0002" >
<OrderLines>
<OrderLine test1="456" />
</OrderLines>
</Order>
</Input>
</API>
</MultiApi>
<MultiApi>
<API>
<Input>
<Order test="0003" >
<OrderLines>
<OrderLine test1="789" />
</OrderLines>
</Order>
</Input>
</API>
</MultiApi>
</Root>
我尝试了以下 XSL - 但返回 null。任何帮助都会很棒:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="tag">
<xsl:value-of select="/*/*/EOF/@MaxMsgPerFile"/>
</xsl:variable>
<xsl:template match="/Root">
<xsl:copy>
<xsl:for-each select="MultiApi[not (EOF)]/API/Input/Order[position() mod $tag = 1]">
<MultiApi>
<xsl:copy-of select="| . | following-sibling::Order[position() < $tag]"/>
</MultiApi>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我可能在“兄弟姐妹”方面做得不好。请审查和帮助!