我正在尝试编写一个 XSLT 来检查 L24/ITEM 段是否重复,如果重复,则我们需要使用一个 ITEM 段创建单独的 L24 段,其余段将相同。这意味着 ITEM 是重复其标题节点 L24 的关键。我的 XSLT 没有给出预期的结果,您能在这里提供帮助吗?
输入:
<?xml version="1.1"?>
<EXTR001>
<DOC BEGIN="1">
<DC4 SEGMENT="1">
<TAB>DC4</TAB>
<MAN>010</MAN>
</DC4>
<L20 SEGMENT="1">
<VBE>424</VBE>
<L22 SEGMENT="1">
<VKORG_BEZ>FIN</VKORG_BEZ>
</L22>
<L24 SEGMENT="1">
<POSNR>000010</POSNR>
<MATNR>000909</MATNR>
<DP05 SEGMENT="1">
<Z1CUSTCODE>340</Z1CUSTCODE>
<QUALF>90</QUALF>
</DP05>
<Z1CUEAN SEGMENT="1">
<Z2CUEAN>871132</Z2CUEAN>
</Z1CUEAN>
<ITEM SEGMENT="1">
<POSNR>000010</POSNR>
<EAN11>87113273</EAN11>
<SSCC>OCR1</SSCC>
</ITEM>
<Z1MBXGLN SEGMENT="1">
<BBBNR>0000000</BBBNR>
</Z1MBXGLN>
<L26 SEGMENT="1">
<PSTYV>Z112</PSTYV>
<L27 SEGMENT="1">
<PRODH_BEZ>Cor</PRODH_BEZ>
</L27>
</L26>
</L24>
<L24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>18830</MATNR>
<DP05 SEGMENT="1">
<Z1CUSTCODE>34720</Z1CUSTCODE>
<QUALF>901</QUALF>
</DP05>
<Z1CUEAN SEGMENT="1">
<Z2CUEAN>0909</Z2CUEAN>
</Z1CUEAN>
<ITEM SEGMENT="1">
<POSNR>000020</POSNR>
<EAN11>8711327347205</EAN11>
<SSCC>1234</SSCC>
</ITEM>
<ITEM SEGMENT="1">
<POSNR>000020</POSNR>
<EAN11>8711327347205</EAN11>
<SSCC>4321</SSCC>
</ITEM>
<Z1MBXGLN SEGMENT="1">
<BBBNR>0000000</BBBNR>
<BBSNR>00000</BBSNR>
</Z1MBXGLN>
<L26 SEGMENT="1">
<PSTYV>Z112</PSTYV>
<MATKL>UNASSIGND</MATKL>
<L27 SEGMENT="1">
<PRODH_BEZ>C13</PRODH_BEZ>
</L27>
</L26>
</L24>
</L20>
</DOC>
</EXTR001>
** 期望输出:**
<?xml version="1.1"?>
<EXTR001>
<DOC BEGIN="1">
<DC4 SEGMENT="1">
<TAB>DC4</TAB>
<MAN>010</MAN>
</DC4>
<L20 SEGMENT="1">
<VBE>424</VBE>
<L22 SEGMENT="1">
<VKORG_BEZ>FIN</VKORG_BEZ>
</L22>
<L24 SEGMENT="1">
<POSNR>000010</POSNR>
<MATNR>000909</MATNR>
<DP05 SEGMENT="1">
<Z1CUSTCODE>340</Z1CUSTCODE>
<QUALF>90</QUALF>
</DP05>
<Z1CUEAN SEGMENT="1">
<Z2CUEAN>871132</Z2CUEAN>
</Z1CUEAN>
<ITEM SEGMENT="1">
<POSNR>000010</POSNR>
<EAN11>87113273</EAN11>
<SSCC>OCR1</SSCC>
</ITEM>
<Z1MBXGLN SEGMENT="1">
<BBBNR>0000000</BBBNR>
</Z1MBXGLN>
<L26 SEGMENT="1">
<PSTYV>Z112</PSTYV>
<L27 SEGMENT="1">
<PRODH_BEZ>Cor</PRODH_BEZ>
</L27>
</L26>
</L24>
<L24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>18830</MATNR>
<DP05 SEGMENT="1">
<Z1CUSTCODE>34720</Z1CUSTCODE>
<QUALF>901</QUALF>
</DP05>
<Z1CUEAN SEGMENT="1">
<Z2CUEAN>0909</Z2CUEAN>
</Z1CUEAN>
<ITEM SEGMENT="1">
<POSNR>000020</POSNR>
<EAN11>8711327347205</EAN11>
<SSCC>1234</SSCC>
</ITEM>
<Z1MBXGLN SEGMENT="1">
<BBBNR>0000000</BBBNR>
<BBSNR>00000</BBSNR>
</Z1MBXGLN>
<L26 SEGMENT="1">
<PSTYV>Z112</PSTYV>
<MATKL>UNASSIGND</MATKL>
<L27 SEGMENT="1">
<PRODH_BEZ>C13</PRODH_BEZ>
</L27>
</L26>
</L24>
<L24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>18830</MATNR>
<DP05 SEGMENT="1">
<Z1CUSTCODE>34720</Z1CUSTCODE>
<QUALF>901</QUALF>
</DP05>
<Z1CUEAN SEGMENT="1">
<Z2CUEAN>0909</Z2CUEAN>
</Z1CUEAN>
<ITEM SEGMENT="1">
<POSNR>000020</POSNR>
<EAN11>8711327347205</EAN11>
<SSCC>4321</SSCC>
</ITEM>
<Z1MBXGLN SEGMENT="1">
<BBBNR>0000000</BBBNR>
<BBSNR>00000</BBSNR>
</Z1MBXGLN>
<L26 SEGMENT="1">
<PSTYV>Z112</PSTYV>
<MATKL>UNASSIGND</MATKL>
<L27 SEGMENT="1">
<PRODH_BEZ>C13</PRODH_BEZ>
</L27>
</L26>
</L24>
</L20>
</DOC>
</EXTR001>
** 我使用的 XSLT 如下:**
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/EXTR001">
<xsl:copy>
<xsl:apply-templates select="EXTR001"/>
<xsl:apply-templates select="ITEM"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ITEM">
<xsl:if test="count(ITEM) >1">
<xsl:apply-templates select="ITEM"/>
</xsl:if>
</xsl:template>
<xsl:template match="ITEM">
<xsl:variable name="EXTR001" select="/EXTR001"/>
<xsl:copy-of select="$EXTR001"/>
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>