为什么XSL:副本不为我工作



i具有以下XSLT,该XSLT包含三个特定元素,然后重命名了更多节点。问题在于它仅包装初始元素,而XSLT的下一部分不运行。如果我评论XSLT的包装部分,则将重命名完成而没有错误。

<?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" omit-xml-declaration="yes" />
    <xsl:strip-space elements="*"/>
    <!-- identity rule Copy all elements and attributes from the source to the target -->
    <xsl:template match="@*|node()" name="identity">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>
    <!-- Wrap Element   -->
    <xsl:template match="/dataroot/qryXMLOrders">
        <xsl:copy>
            <xsl:copy-of select="PreDocTypAR21/preceding-sibling::*"/>
            <PREADMREFAR2>
                <xsl:copy-of select="PreDocTypAR21|PreDocRefAR26|PreDocCatPREADMREF21"/>
            </PREADMREFAR2>
            <xsl:copy-of select="PreDocCatPREADMREF21/following-sibling::*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/dataroot/qryXMLOrders/DocTypDC21A">
        <DocTypDC21>
            <xsl:apply-templates select="@* | node()"/>
        </DocTypDC21>
    </xsl:template>
    <xsl:template match="/dataroot/qryXMLOrders/DocRefDC23A">
        <DocRefDC23>
            <xsl:apply-templates select="@*|node()" />
        </DocRefDC23>
    </xsl:template>
    <xsl:template match="/dataroot/qryXMLOrders/DocTypDC21B">
        <DocTypDC21>
            <xsl:apply-templates select="@*|node()" />
        </DocTypDC21>
    </xsl:template>
    <xsl:template match="/dataroot/qryXMLOrders/DocRefDC23B">
        <DocRefDC23>
            <xsl:apply-templates select="@*|node()" />
        </DocRefDC23>
    </xsl:template>
</xsl:stylesheet>

root元素是" dataroot",所有其他元素都在" qryxmlorders"内部,该元素重复

所以我想转换的XML的一部分就像是这样

<dataroot generated="2017-03-11T14:06:08" xmlns:od="urn:schemas-microsoft-com:officedata">
    <qryXMLOrders>
        <IteNumGDS7>1</IteNumGDS7>
        <GroMasGDS46>0.046</GroMasGDS46>
        <NetMasGDS48>0.01</NetMasGDS48>
        <ProReqGDI1>10</ProReqGDI1>
        <PreProGDI1>00</PreProGDI1>
        <ComNatProGIM1>000</ComNatProGIM1>
        <StaValAmoGDI1>17.04</StaValAmoGDI1>
        <PreDocTypAR21>380</PreDocTypAR21>
        <PreDocRefAR26>6376</PreDocRefAR26>
        <PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
        <DocTypDC21>N380</DocTypDC21>
        <DocRefDC23>6376</DocRefDC23>
        <DocTypDC21A>Y900</DocTypDC21A>
        <DocRefDC23A>-</DocRefDC23A>
        <DocTypDC21B>Y922</DocTypDC21B>
        <DocRefDC23B>-</DocRefDC23B>
        <ComNomCMD1>71171900</ComNomCMD1>
        <TARCodCMD1>00</TARCodCMD1>
        <TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
        <TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
        <NAtAddCodCMD1>0000</NAtAddCodCMD1>
        <NamCE27>Martha</NamCE27>
        <StrAndNumCE222>apt 5F</StrAndNumCE222>
        <PosCodCE223>10034</PosCodCE223>
        <CitCE224>New York</CitCE224>
        <CouCE225>US</CouCE225>
        <NADLNGGICE>EN</NADLNGGICE>
        <MarNumOfPacGS21>RE5935</MarNumOfPacGS21>
        <KinOfPacGS23>EN</KinOfPacGS23>
        <NumOfPacGS24>1</NumOfPacGS24>
        <InvoiceDate>2017-03-10T00:00:00</InvoiceDate>
    </qryXMLOrders>
    <qryXMLOrders>
        <IteNumGDS7>1</IteNumGDS7>
        <GroMasGDS46>0.046</GroMasGDS46>
        <NetMasGDS48>0.01</NetMasGDS48>
        <ProReqGDI1>10</ProReqGDI1>
        <PreProGDI1>00</PreProGDI1>
        <ComNatProGIM1>000</ComNatProGIM1>
        <StaValAmoGDI1>18.85</StaValAmoGDI1>
        <PreDocTypAR21>380</PreDocTypAR21>
        <PreDocRefAR26>6379</PreDocRefAR26>
        <PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
        <DocTypDC21>N380</DocTypDC21>
        <DocRefDC23>6379</DocRefDC23>
        <DocTypDC21A>Y900</DocTypDC21A>
        <DocRefDC23A>-</DocRefDC23A>
        <DocTypDC21B>Y922</DocTypDC21B>
        <DocRefDC23B>-</DocRefDC23B>
        <ComNomCMD1>71171900</ComNomCMD1>
        <TARCodCMD1>00</TARCodCMD1>
        <TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
        <TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
        <NAtAddCodCMD1>0000</NAtAddCodCMD1>
        <NamCE27>fgfgfgf</NamCE27>
        <StrAndNumCE222>507 E Water St</StrAndNumCE222>
        <PosCodCE223>77901-9257</PosCodCE223>
        <CitCE224>Victoria</CitCE224>
        <CouCE225>US</CouCE225>
        <NADLNGGICE>EN</NADLNGGICE>
        <MarNumOfPacGS21>RE59357</MarNumOfPacGS21>
        <KinOfPacGS23>EN</KinOfPacGS23>
        <NumOfPacGS24>1</NumOfPacGS24>
        <InvoiceDate>2017-03-10T00:00:00</InvoiceDate>
    </qryXMLOrders>
</dataroot>

和XSLT之后的所需结果:

<dataroot generated="2017-03-11T14:06:08" xmlns:od="urn:schemas-microsoft-com:officedata">
    <qryXMLOrders>
        <IteNumGDS7>1</IteNumGDS7>
        <GroMasGDS46>0.046</GroMasGDS46>
        <NetMasGDS48>0.01</NetMasGDS48>
        <ProReqGDI1>10</ProReqGDI1>
        <PreProGDI1>00</PreProGDI1>
        <ComNatProGIM1>000</ComNatProGIM1>
        <StaValAmoGDI1>17.04</StaValAmoGDI1>
        <PREADMREFAR2>
            <PreDocTypAR21>380</PreDocTypAR21>
            <PreDocRefAR26>6376</PreDocRefAR26>
            <PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
        </PREADMREFAR2>
        <DocTypDC21>N380</DocTypDC21>
        <DocRefDC23>6376</DocRefDC23>
        <DocTypDC21>Y900</DocTypDC21>
        <DocRefDC23>-</DocRefDC23>
        <DocTypDC21>Y922</DocTypDC21>
        <DocRefDC23>-</DocRefDC23>
        <ComNomCMD1>71171900</ComNomCMD1>
        <TARCodCMD1>00</TARCodCMD1>
        <TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
        <TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
        <NAtAddCodCMD1>0000</NAtAddCodCMD1>
        <NamCE27>Martha</NamCE27>
        <StrAndNumCE222>apt 5F</StrAndNumCE222>
        <PosCodCE223>10034</PosCodCE223>
        <CitCE224>New York</CitCE224>
        <CouCE225>US</CouCE225>
        <NADLNGGICE>EN</NADLNGGICE>
        <MarNumOfPacGS21>RE5935</MarNumOfPacGS21>
        <KinOfPacGS23>EN</KinOfPacGS23>
        <NumOfPacGS24>1</NumOfPacGS24>
        <InvoiceDate>2017-03-10T00:00:00</InvoiceDate>
    </qryXMLOrders>
    <qryXMLOrders>
        <IteNumGDS7>1</IteNumGDS7>
        <GroMasGDS46>0.046</GroMasGDS46>
        <NetMasGDS48>0.01</NetMasGDS48>
        <ProReqGDI1>10</ProReqGDI1>
        <PreProGDI1>00</PreProGDI1>
        <ComNatProGIM1>000</ComNatProGIM1>
        <StaValAmoGDI1>18.85</StaValAmoGDI1>
        <PREADMREFAR2>
            <PreDocTypAR21>380</PreDocTypAR21>
            <PreDocRefAR26>6379</PreDocRefAR26>
            <PreDocCatPREADMREF21>Z</PreDocCatPREADMREF21>
        </PREADMREFAR2>
        <DocTypDC21>N380</DocTypDC21>
        <DocRefDC23>6379</DocRefDC23>
        <DocTypDC21>Y900</DocTypDC21>
        <DocRefDC23>-</DocRefDC23>
        <DocTypDC21>Y922</DocTypDC21>
        <DocRefDC23>-</DocRefDC23>
        <ComNomCMD1>71171900</ComNomCMD1>
        <TARCodCMD1>00</TARCodCMD1>
        <TARFirAddCodCMD1>0000</TARFirAddCodCMD1>
        <TARSecAddCodCMD1>0000</TARSecAddCodCMD1>
        <NAtAddCodCMD1>0000</NAtAddCodCMD1>
        <NamCE27>fgfgfgf</NamCE27>
        <StrAndNumCE222>507 E Water St</StrAndNumCE222>
        <PosCodCE223>77901-9257</PosCodCE223>
        <CitCE224>Victoria</CitCE224>
        <CouCE225>US</CouCE225>
        <NADLNGGICE>EN</NADLNGGICE>
        <MarNumOfPacGS21>RE59357</MarNumOfPacGS21>
        <KinOfPacGS23>EN</KinOfPacGS23>
        <NumOfPacGS24>1</NumOfPacGS24>
        <InvoiceDate>2017-03-10T00:00:00</InvoiceDate>
    </qryXMLOrders>
</dataroot>

非常感谢,Nikos

由于您的模板匹配包装节点,因此需要在使用包装的模板中使用xsl:apply-templates而不是xsl:copy-of

相关内容

  • 没有找到相关文章