Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML转换在不同的部分复制一个元素两次_Xml_Xslt_Copy_Transformation - Fatal编程技术网

XML转换在不同的部分复制一个元素两次

XML转换在不同的部分复制一个元素两次,xml,xslt,copy,transformation,Xml,Xslt,Copy,Transformation,我有一个XML,它需要一些转换才能正确地导入到我们的数据库中。我做了大部分更改,但在ApprovedCountry标记中复制一个元素E100customerKey时遇到问题。不知道如何在文件的这一部分复制它。请参阅下面的代码: 从合作伙伴处收到的示例代码: <?xml version="1.0" encoding="UTF-8"?> <CustomerList> <TransferHeader> <Apllication>A

我有一个XML,它需要一些转换才能正确地导入到我们的数据库中。我做了大部分更改,但在ApprovedCountry标记中复制一个元素E100customerKey时遇到问题。不知道如何在文件的这一部分复制它。请参阅下面的代码:

从合作伙伴处收到的示例代码:

<?xml version="1.0" encoding="UTF-8"?>
<CustomerList>
    <TransferHeader>
        <Apllication>ApllicationForTransferCustomer</Apllication>
        <Sender>Partenr</Sender>
        <MailAdr>mail@mail.pl</MailAdr>
        <GeneratedDate>20160114</GeneratedDate>
        <NumberOfCustomers>3</NumberOfCustomers>
    </TransferHeader>
    <CustomerList>
        <Customer>
            <E100customerKey>03-98</E100customerKey>
            <VATNumber>2222222222</VATNumber>
            <EUVATNumber>11111111111</EUVATNumber>
            <CustomerName1>CustomerName</CustomerName1>
            <LineOfBusiness>uslugi transportowe</LineOfBusiness>
            <NACEcode>4941</NACEcode>
            <RequiredForPrivateCompany/>
            <ApprovedCountriesList>
                <ApprovedCountry>
                    <CountryCode>ES</CountryCode>
                    <ServiceType>Normal</ServiceType>
                    <PartnerPercent>3</PartnerPercent>
                </ApprovedCountry>
            </ApprovedCountriesList>
        </Customer>
    </CustomerList>
</CustomerList>
所需代码:

<?xml version="1.0" encoding="UTF-8"?>
<CustomerList>
    <CustomerList>
        <Customer>
            <E100customerKey>03-98</E100customerKey>
            <VATNumber>2222222222</VATNumber>
            <EUVATNumber>11111111111</EUVATNumber>
            <CustomerName1>CustomerName</CustomerName1>
            <LineOfBusiness>uslugi transportowe</LineOfBusiness>
            <NACEcode>4941</NACEcode>
            <ApprovedCountriesList>
                <ApprovedCountry>
                    <E100customerKey>03-98</E100customerKey>
                    <CountryCode>ES</CountryCode>
                    <ServiceType>Normal</ServiceType>
                    <PartnerPercent>3</PartnerPercent>
                </ApprovedCountry>
            </ApprovedCountriesList>
        </Customer>
    </CustomerList>
</CustomerList>
到目前为止,我的XSL文件:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes" encoding="UTF-8" />

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

<!-- Probably needs to fix this part -->
 <xsl:template match="CustomerList/CustomerList/Customer/ApprovedCountriesList/ApprovedCountry">
  </xsl:template>

 <xsl:template match="CustomerList/TransferHeader|RequiredForPrivateCompany"/>
</xsl:stylesheet>
尝试:

XSLT1.0

尝试:

XSLT1.0


您的输出与输入不匹配-例如,输入或XSLT中没有21-400。@michael.hor257k是的,您是对的,我想修剪XML以删除不必要的信息。将问题编辑为现在应该匹配。您的输出与输入不匹配-例如,输入或XSLT中没有21-400。@michael.hor257k是的,您是对的,我想修剪XML以删除不必要的信息。将问题编辑为现在应该匹配。效果完美。如果我想更改重复标签的名称,说明中应该更改什么?非常有效。如果我想更改重复标签的名称,说明中应该更改什么?
<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:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="TransferHeader | RequiredForPrivateCompany"/>

<xsl:template match="ApprovedCountry">
    <xsl:copy>
        <xsl:copy-of select="../../E100customerKey"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>