将默认命名空间声明从XSLT转换为XML

时间:2017-01-24 19:22:40

标签: xslt xslt-2.0

我的第一篇文章。在开始之前,我会承认我已经破解了我的XSLT定义。而且我对命名空间没有很好的理解。

我正在使用XSLT转换XML。我需要一个默认命名空间出现在我的结果XML中。默认名称空间为:

的xmlns =" HTTP://www.bmecat.org/bmecat/2005fd"

没有此命名空间,我的转换工作正常。但是当我将它添加到我的XSLT时,我最终会出现一个空的xmlns =""我的节点名称的属性。我已阅读了很多帖子,他们都告诉你在命名空间中添加前缀。但我无法添加一个。我需要将我的命名空间显示在xml中,如上所示。

这里是XSLT标题:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns="http://www.bmecat.org/bmecat/2005fd"
>
<!-- Format for output document -->
<xsl:output method="xml" indent="yes"/>

<!-- Find the ROOT element and data underneath it -->
<xsl:template match="ROOT">


    <!-- BMEcat XML output -->
    <BMECAT version="2005">

        <!-- Header information -->
        <HEADER>


            <!-- Copy the BUYER nodes -->
            <xsl:copy-of select="BUYER"/>

它为XML生成正确的标头。但是,它会影响具有空属性的节点名称:

<?xml version="1.0" encoding="utf-8"?>
<BMECAT version="2005" 
  xmlns="http://www.bmecat.org/bmecat/2005fd" 
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>
  <HEADER>
    <BUYER xmlns="">
      <BUYER_NAME>XYZ</BUYER_NAME>
    </BUYER>

如何在不使用前缀的情况下将名称空间保留在xml输出头中,从而摆脱空的xmlns属性?

全部谢谢

这是完整的模板:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns="http://www.bmecat.org/bmecat/2005fd"
    >
    <!-- Format for output document -->
    <xsl:output method="xml" indent="yes"/>

    <!-- ISO 639-2 Lanugate code lookup -->
     <xsl:variable name="langMap">
    <entry key="EN">eng</entry>
    <entry key="DE">deu</entry>
    <entry key="ES">spa</entry>
        <entry key="FR">fra</entry>
        <entry key="IT">ita</entry>
        <entry key="JA">jpn</entry>
        <entry key="PT">por</entry>
        <entry key="RU">rus</entry>
        <entry key="ZH">zho</entry>
    </xsl:variable>

    <!-- Find the ROOT element and data underneath it -->
    <xsl:template match="ROOT">

        <!-- Declare a variable for date -->
        <xsl:param name="date"><xsl:value-of select="timestamp" /></xsl:param>

        <!-- BMEcat XML output -->
        <BMECAT version="2005">

            <!-- Header information -->
            <HEADER>
                <CATALOG>
                    <LANGUAGE>eng</LANGUAGE>
                    <CATALOG_ID>001.001</CATALOG_ID>
                    <CATALOG_VERSION>001.027</CATALOG_VERSION>
                    <CATALOG_NAME>Mersen-BMEcat</CATALOG_NAME>
                    <DATETIME type="generation_date">
                        <DATE>
                            <xsl:value-of select="substring-before($date,'T')" />
                        </DATE>
                    </DATETIME>
                    <TERRITORY>GB</TERRITORY>
                    <CURRENCY>EUR</CURRENCY>
                </CATALOG>

                <!-- Copy the BUYER nodes -->
                <xsl:template match="BUYER">
                    <xsl:copy>
                        <xsl:apply-templates/>
                    </xsl:copy>
                </xsl:template>



                <!-- Copy the SUPPLIER nodes -->
                <xsl:copy-of select="SUPPLIER"/>

                <!-- Copy the MIME_INFO nodes -->
                <xsl:copy-of select="MIME_INFO"/>

                <USER_DEFINED_EXTENSIONS>
                    <UDX.EDXF.VERSION>3.1</UDX.EDXF.VERSION>
                </USER_DEFINED_EXTENSIONS>
            </HEADER>

            <!-- Product Information Section -->
            <T_NEW_CATALOG>

                <!-- Cycle for each of the PRODUCT_ITEM in the output -->
                <xsl:for-each select="/ROOT/PRODUCT_ITEM">

                    <!-- Create a PRODUCT Element -->
                    <PRODUCT mode="new">

                        <!-- PRODUCT level propertes -->
                        <SUPPLIER_PID><xsl:value-of select="ITEM_NUMBER" /></SUPPLIER_PID>

                        <!-- PRODUCT DETAILS properties-->
                        <PRODUCT_DETAILS>

                            <DESCRIPTION_SHORT><xsl:value-of select="SHORT_DESCRIPTION__80MAX_EN" /></DESCRIPTION_SHORT>

                            <!-- Code for multilingual DESCRIPTION_LONG, change the first two lines for other properties -->
                            <xsl:variable name="tagName">LONG_DESCRIPTION_</xsl:variable>
                            <xsl:variable name="elemName">DESCRIPTION_LONG</xsl:variable>
                            <xsl:for-each select="node()[starts-with(name(), $tagName)]">
                                <xsl:variable name="nodename" >
                                    <xsl:value-of select="name()"/>
                                </xsl:variable>
                                <xsl:variable name = "langCode2" select="substring-after($nodename,$tagName)"></xsl:variable>
                                <xsl:variable name = "langCode3" select="msxsl:node-set($langMap)/entry[@key=$langCode2]"/>
                                <xsl:element name="{$elemName}">
                                    <xsl:attribute name="lang"><xsl:value-of select="$langCode3" /></xsl:attribute>
                                    <xsl:value-of select="node()"/>
                                </xsl:element>
                            </xsl:for-each>

                            <!-- Properties -->
                            <xsl:if test="EAN_UPC_CODE != ''">
                                <INTERNATIONAL_PID type="GTIN"><xsl:value-of select="EAN_UPC_CODE" /></INTERNATIONAL_PID>
                            </xsl:if>   
                            <xsl:if test="REF_NO != ''">
                                <SUPPLIER_ALT_PID><xsl:value-of select="REF_NO" /></SUPPLIER_ALT_PID>
                            </xsl:if>
                            <xsl:if test="CATALOGUE_NO_ != ''">
                                <MANUFACTURER_TYPE_DESCR><xsl:value-of select="CATALOGUE_NO_" /></MANUFACTURER_TYPE_DESCR>
                            </xsl:if>

                            <!-- Code for multilingual KEYWORD, change the first two lines for other properties -->
                            <xsl:variable name="tagName2">KEYWORD_</xsl:variable>
                            <xsl:variable name="elemName2">KEYWORD</xsl:variable>
                            <xsl:for-each select="node()[starts-with(name(), $tagName2)]">
                                <xsl:variable name="nodename" >
                                    <xsl:value-of select="name()"/>
                                </xsl:variable>
                                <xsl:variable name = "langCode2" select="substring-after($nodename,$tagName2)"></xsl:variable>
                                <xsl:variable name = "langCode3" select="msxsl:node-set($langMap)/entry[@key=$langCode2]"/>
                                <xsl:element name="{$elemName2}">
                                    <xsl:attribute name="lang"><xsl:value-of select="$langCode3" /></xsl:attribute>
                                    <xsl:value-of select="node()"/>
                                </xsl:element>
                            </xsl:for-each>

                            <PRODUCT_STATUS type="new">New</PRODUCT_STATUS>

                        </PRODUCT_DETAILS>

                        <!-- PRODUCT FEATURES properties-->
                        <PRODUCT_FEATURES>
                            <REFERENCE_FEATURE_SYSTEM_NAME>ETIM-6.0</REFERENCE_FEATURE_SYSTEM_NAME>
                            <REFERENCE_FEATURE_GROUP_ID><xsl:value-of select="ETIM_CLASS" /></REFERENCE_FEATURE_GROUP_ID>
                             <xsl:for-each select="FEATURE">
                                 <xsl:copy-of select="." />
                            </xsl:for-each>
                        </PRODUCT_FEATURES>

                        <!-- PRODUCT ORDER Details-->
                        <PRODUCT_ORDER_DETAILS>
                            <ORDER_UNIT>C62</ORDER_UNIT>
                            <CONTENT_UNIT>C62</CONTENT_UNIT>
                            <NO_CU_PER_OU>1</NO_CU_PER_OU>
                            <PRICE_QUANTITY>1</PRICE_QUANTITY>
                            <QUANTITY_MIN><xsl:value-of select="SELL_PACK_QUANTITY" /></QUANTITY_MIN>
                            <QUANTITY_INTERVAL><xsl:value-of select="SELL_PACK_QUANTITY" /></QUANTITY_INTERVAL>
                        </PRODUCT_ORDER_DETAILS>

                        <!-- PRODUCT ORDER Details-->
                        <PRODUCT_PRICE_DETAILS>
                            <DATETIME type="valid_start_date">
                                <DATE><xsl:value-of select="substring-before($date,'T')" /></DATE>
              </DATETIME>
                            <PRODUCT_PRICE price_type="nrp">
                                 <PRICE_AMOUNT>1</PRICE_AMOUNT>
                            </PRODUCT_PRICE>
                        </PRODUCT_PRICE_DETAILS>

                        <!-- MIME INFO -->
                        <xsl:for-each select="MIME_INFO">
                            <MIME_INFO>
                                <xsl:copy-of select="*" />
                            </MIME_INFO>
                        </xsl:for-each> 

                        <!-- USER_DEFINED_EXTENSIONS -->
                        <USER_DEFINED_EXTENSIONS>
                            <UDX.EDXF.MANUFACTURER_ACRONYM>Mersen</UDX.EDXF.MANUFACTURER_ACRONYM>
                            <UDX.EDXF.DESCRIPTION_VERY_SHORT><xsl:value-of select="ITEM_DESCRIPTION__ERP_EN" /></UDX.EDXF.DESCRIPTION_VERY_SHORT>
                            <UDX.EDXF.BRAND_NAME><xsl:value-of select="BRAND_NAME" /></UDX.EDXF.BRAND_NAME>
                            <UDX.EDXF.PACKING_UNITS>
                                <UDX.EDXF.PACKING_UNIT>
                                    <UDX.EDXF.QUANTITY_MIN><xsl:value-of select="SELL_PACK_QUANTITY" /></UDX.EDXF.QUANTITY_MIN>
                                    <UDX.EDXF.QUANTITY_MAX><xsl:value-of select="SELL_PACK_QUANTITY" /></UDX.EDXF.QUANTITY_MAX>
                                    <UDX.EDXF.PACKING_UNIT_CODE><xsl:value-of select="SELL_PACK_QUANTITY_UOM" /></UDX.EDXF.PACKING_UNIT_CODE>
                                    <UDX.EDXF.WEIGHT><xsl:value-of select="SELL_PACK_WEIGHT" /></UDX.EDXF.WEIGHT>
                                    <UDX.EDXF.LENGTH><xsl:value-of select="SELL_PACK_LENGTH" /></UDX.EDXF.LENGTH>
                                    <UDX.EDXF.WIDTH><xsl:value-of select="SELL_PACK_WIDTH" /></UDX.EDXF.WIDTH>
                                    <UDX.EDXF.DEPTH><xsl:value-of select="SELL_PACK_HEIGHT" /></UDX.EDXF.DEPTH>
                                    <UDX.EDXF.GTIN><xsl:value-of select="GTIN_SELL_PACK" /></UDX.EDXF.GTIN>
                                </UDX.EDXF.PACKING_UNIT>
                            </UDX.EDXF.PACKING_UNITS>
                            <UDX.EDXF.PRODUCT_LOGISTIC_DETAILS>
                                <UDX.EDXF.NETWEIGHT><xsl:value-of select="PRODUCT_WEIGHT" /></UDX.EDXF.NETWEIGHT>
                            </UDX.EDXF.PRODUCT_LOGISTIC_DETAILS>
                            <UDX.EDXF.REACH>
                                <UDX.EDXF.REACH.LISTDATE><xsl:value-of select="substring-before($date,'T')" /></UDX.EDXF.REACH.LISTDATE>
                                <UDX.EDXF.REACH.INFO>no data</UDX.EDXF.REACH.INFO>
                            </UDX.EDXF.REACH>
                        </USER_DEFINED_EXTENSIONS>

                        <!-- Product Logistic Details -->                   
                        <PRODUCT_LOGISTIC_DETAILS>
                            <CUSTOMS_TARIFF_NUMBER>
                                <CUSTOMS_NUMBER><xsl:value-of select="EU_CUSTOMS_CODE" /></CUSTOMS_NUMBER>
                            </CUSTOMS_TARIFF_NUMBER>
                            <COUNTRY_OF_ORIGIN><xsl:value-of select="COUNTRY_OF_ORIGIN" /></COUNTRY_OF_ORIGIN>
                        </PRODUCT_LOGISTIC_DETAILS>
                    </PRODUCT>
                </xsl:for-each>
            </T_NEW_CATALOG>
        </BMECAT>
    </xsl:template>
</xsl:stylesheet>

这是原始XML:

<?xml version="1.0" encoding="utf-8"?>
<ROOT>
  <timestamp>2017-01-24T16:04:37</timestamp>
  <BUYER>
    <BUYER_NAME>XYZ</BUYER_NAME>
  </BUYER>
  <SUPPLIER>
    <SUPPLIER_ID type="duns">328546853</SUPPLIER_ID>
    <SUPPLIER_NAME>Mersen</SUPPLIER_NAME>
    <ADDRESS type="supplier">
      <CONTACT>Susan Tichy</CONTACT>
      <STREET>Lienfeldergasse 31-33</STREET>
      <ZIP>1160</ZIP>
      <CITY>WIEN</CITY>
      <COUNTRY>Austria</COUNTRY>
      <EMAIL>susanne.tichy@mersen.com</EMAIL>
      <URL>www.mersen.com</URL>
    </ADDRESS>
  </SUPPLIER>
  <PRODUCT_ITEM>
    <ITEM_NUMBER>A480T5E</ITEM_NUMBER>
    <BRAND_NAME>Mersen</BRAND_NAME>
    <COUNTRY_OF_ORIGIN>MX</COUNTRY_OF_ORIGIN>
    <ETIM_CLASS>EC000055</ETIM_CLASS>
    <LONG_DESCRIPTION_EN>Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</LONG_DESCRIPTION_EN>
    <LONG_DESCRIPTION_FR>French description</LONG_DESCRIPTION_FR>
    <LONG_DESCRIPTION_DE>Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</LONG_DESCRIPTION_DE>
    <LONG_DESCRIPTION_IT>Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</LONG_DESCRIPTION_IT>
    <LONG_DESCRIPTION_JA>Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</LONG_DESCRIPTION_JA>
    <PRODUCT_BRAND>Amp-Trap®</PRODUCT_BRAND>
    <SUPPORT_BRAND>Ferraz Shawmut</SUPPORT_BRAND>
    <PRODUCT_WEIGHT>0.1814368</PRODUCT_WEIGHT>
    <PRODUCT_WEIGHT_UOM>KGM</PRODUCT_WEIGHT_UOM>
    <SELL_PACK_DESCRIPTION>Box</SELL_PACK_DESCRIPTION>
    <SELL_PACK_HEIGHT>0.06985</SELL_PACK_HEIGHT>
    <SELL_PACK_HEIGHT_UOM>MTR</SELL_PACK_HEIGHT_UOM>
    <SELL_PACK_LENGTH>0.2032</SELL_PACK_LENGTH>
    <SELL_PACK_LENGTH_UOM>MTR</SELL_PACK_LENGTH_UOM>
    <SELL_PACK_WIDTH>0.1016</SELL_PACK_WIDTH>
    <SELL_PACK_WIDTH_UOM>MTR</SELL_PACK_WIDTH_UOM>
    <SELL_PACK_QUANTITY>2</SELL_PACK_QUANTITY>
    <SELL_PACK_QUANTITY_UOM>C62</SELL_PACK_QUANTITY_UOM>
    <SELL_PACK_WEIGHT>0.38101728</SELL_PACK_WEIGHT>
    <SELL_PACK_WEIGHT_UOM>KGM</SELL_PACK_WEIGHT_UOM>
    <FEATURE>
      <FNAME PIM_name="AMPERE_RATING">EF000227</FNAME>
      <FVALUE PIM_value="5">5</FVALUE>
      <FUNIT PIM_unit="A">EU570459</FUNIT>
    </FEATURE>
    <ARTICLE_NO>M217959B</ARTICLE_NO>
    <CATALOGUE_NO_>M217959A</CATALOGUE_NO_>
    <EAN_UPC_CODE>068938800574</EAN_UPC_CODE>
    <EU_CUSTOMS_CODE>85351000</EU_CUSTOMS_CODE>
    <GTIN_SELL_PACK>30068938800575</GTIN_SELL_PACK>
    <ITEM_DESCRIPTION__ERP_EN>4800V E-RATED FUSE 5E</ITEM_DESCRIPTION__ERP_EN>
    <ITEM_DESCRIPTION__ERP_FR>4800V E-RATED FUSE 5E</ITEM_DESCRIPTION__ERP_FR>
    <ITEM_DESCRIPTION__ERP_DE>4800V E-RATED FUSE 5E</ITEM_DESCRIPTION__ERP_DE>
    <ITEM_DESCRIPTION__ERP_IT>4800V E-RATED FUSE 5E</ITEM_DESCRIPTION__ERP_IT>
    <ITEM_DESCRIPTION__ERP_JA>4800V E-RATED FUSE 5E</ITEM_DESCRIPTION__ERP_JA>
    <MINIMUM_QUANTITY_PER_ORDER>2</MINIMUM_QUANTITY_PER_ORDER>
    <ORDER_MULTIPLE>2</ORDER_MULTIPLE>
    <REF_NO>M217959</REF_NO>
    <SHORT_DESCRIPTION__80MAX_EN>4800V E-RATED FUSE 5E - short description</SHORT_DESCRIPTION__80MAX_EN>
    <SHORT_DESCRIPTION__80MAX_FR>4800V E-RATED FUSE 5E - short description</SHORT_DESCRIPTION__80MAX_FR>
    <SHORT_DESCRIPTION__80MAX_DE>4800V E-RATED FUSE 5E - short description</SHORT_DESCRIPTION__80MAX_DE>
    <SHORT_DESCRIPTION__80MAX_IT>4800V E-RATED FUSE 5E - short description</SHORT_DESCRIPTION__80MAX_IT>
    <SHORT_DESCRIPTION__80MAX_JA>4800V E-RATED FUSE 5E - short description</SHORT_DESCRIPTION__80MAX_JA>
    <KEYWORD_EN>English Keyword1</KEYWORD_EN>
    <KEYWORD_EN>English Keyword2</KEYWORD_EN>
    <KEYWORD_DE>German Keyword1</KEYWORD_DE>
    <KEYWORD_IT>Italian Keyword 3</KEYWORD_IT>
  </PRODUCT_ITEM>
</ROOT>

这是所需的输出。请注意没有空属性的标签。

第二个问题是使用和元素打印的属性。我不希望复制属性。此输出显示了它应该如何。

&LT;

BUYER>
        <BUYER_NAME>XYZ</BUYER_NAME>
      </BUYER>

    <?xml version="1.0" encoding="utf-8"?>
    <BMECAT version="2005" xmlns="http://www.bmecat.org/bmecat/2005fd" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
      <HEADER>
        <CATALOG>
          <LANGUAGE>eng</LANGUAGE>
          <CATALOG_ID>001.001</CATALOG_ID>
          <CATALOG_VERSION>001.027</CATALOG_VERSION>
          <CATALOG_NAME>Mersen-BMEcat</CATALOG_NAME>
          <DATETIME type="generation_date">
            <DATE>2017-01-24</DATE>
          </DATETIME>
          <TERRITORY>GB</TERRITORY>
          <CURRENCY>EUR</CURRENCY>
        </CATALOG>
        <ROOT>
          <BUYER>
            <BUYER_NAME>XYZ</BUYER_NAME>
          </BUYER>
        </ROOT>
        <SUPPLIER>
          <SUPPLIER_ID type="duns">328546853</SUPPLIER_ID>
          <SUPPLIER_NAME>Mersen</SUPPLIER_NAME>
          <ADDRESS type="supplier">
            <CONTACT>Susan Tichy</CONTACT>
            <STREET>Lienfeldergasse 31-33</STREET>
            <ZIP>1160</ZIP>
            <CITY>WIEN</CITY>
            <COUNTRY>Austria</COUNTRY>
            <EMAIL>susanne.tichy@mersen.com</EMAIL>
            <URL>www.mersen.com</URL>
          </ADDRESS>
        </SUPPLIER>
        <USER_DEFINED_EXTENSIONS>
          <UDX.EDXF.VERSION>3.1</UDX.EDXF.VERSION>
        </USER_DEFINED_EXTENSIONS>
      </HEADER>
      <T_NEW_CATALOG>
        <PRODUCT mode="new">
          <SUPPLIER_PID>A480T5E</SUPPLIER_PID>
          <PRODUCT_DETAILS>
            <DESCRIPTION_SHORT>4800V E-RATED FUSE 5E - short description</DESCRIPTION_SHORT>
            <DESCRIPTION_LONG lang="">Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</DESCRIPTION_LONG>
            <DESCRIPTION_LONG lang="">French description</DESCRIPTION_LONG>
            <DESCRIPTION_LONG lang="">Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</DESCRIPTION_LONG>
            <DESCRIPTION_LONG lang="">Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</DESCRIPTION_LONG>
            <DESCRIPTION_LONG lang="">Mersen PT fuses are current-limiting fuses with high interrupting rating, used for the primary winding protection of potential transformer. They are small dimension ferrule type fuses and mount in standard clips. Current ratings are from 0.25A to 5A.</DESCRIPTION_LONG>
            <INTERNATIONAL_PID type="GTIN">068938800574</INTERNATIONAL_PID>
            <SUPPLIER_ALT_PID>M217959</SUPPLIER_ALT_PID>
            <MANUFACTURER_TYPE_DESCR>M217959A</MANUFACTURER_TYPE_DESCR>
            <KEYWORD lang="">English Keyword1</KEYWORD>
            <KEYWORD lang="">English Keyword2</KEYWORD>
            <KEYWORD lang="">German Keyword1</KEYWORD>
            <KEYWORD lang="">Italian Keyword 3</KEYWORD>
            <PRODUCT_STATUS type="new">New</PRODUCT_STATUS>
          </PRODUCT_DETAILS>
          <PRODUCT_FEATURES>
            <REFERENCE_FEATURE_SYSTEM_NAME>ETIM-6.0</REFERENCE_FEATURE_SYSTEM_NAME>
            <REFERENCE_FEATURE_GROUP_ID>EC000055</REFERENCE_FEATURE_GROUP_ID>
            <FEATURE>
              <FNAME>EF000227</FNAME>
              <FVALUE>5</FVALUE>
              <FUNIT>EU570459</FUNIT>
            </FEATURE>
          </PRODUCT_FEATURES>
          <PRODUCT_ORDER_DETAILS>
            <ORDER_UNIT>C62</ORDER_UNIT>
            <CONTENT_UNIT>C62</CONTENT_UNIT>
            <NO_CU_PER_OU>1</NO_CU_PER_OU>
            <PRICE_QUANTITY>1</PRICE_QUANTITY>
            <QUANTITY_MIN>2</QUANTITY_MIN>
            <QUANTITY_INTERVAL>2</QUANTITY_INTERVAL>
          </PRODUCT_ORDER_DETAILS>
          <PRODUCT_PRICE_DETAILS>
            <DATETIME type="valid_start_date">
              <DATE>2017-01-24</DATE>
            </DATETIME>
            <PRODUCT_PRICE price_type="nrp">
              <PRICE_AMOUNT>1</PRICE_AMOUNT>
            </PRODUCT_PRICE>
          </PRODUCT_PRICE_DETAILS>
          <USER_DEFINED_EXTENSIONS>
            <UDX.EDXF.MANUFACTURER_ACRONYM>Mersen</UDX.EDXF.MANUFACTURER_ACRONYM>
            <UDX.EDXF.DESCRIPTION_VERY_SHORT>4800V E-RATED FUSE 5E</UDX.EDXF.DESCRIPTION_VERY_SHORT>
            <UDX.EDXF.BRAND_NAME>Mersen</UDX.EDXF.BRAND_NAME>
            <UDX.EDXF.PACKING_UNITS>
              <UDX.EDXF.PACKING_UNIT>
                <UDX.EDXF.QUANTITY_MIN>2</UDX.EDXF.QUANTITY_MIN>
                <UDX.EDXF.QUANTITY_MAX>2</UDX.EDXF.QUANTITY_MAX>
                <UDX.EDXF.PACKING_UNIT_CODE>C62</UDX.EDXF.PACKING_UNIT_CODE>
                <UDX.EDXF.WEIGHT>0.38101728</UDX.EDXF.WEIGHT>
                <UDX.EDXF.LENGTH>0.2032</UDX.EDXF.LENGTH>
                <UDX.EDXF.WIDTH>0.1016</UDX.EDXF.WIDTH>
                <UDX.EDXF.DEPTH>0.06985</UDX.EDXF.DEPTH>
                <UDX.EDXF.GTIN>30068938800575</UDX.EDXF.GTIN>
              </UDX.EDXF.PACKING_UNIT>
            </UDX.EDXF.PACKING_UNITS>
            <UDX.EDXF.PRODUCT_LOGISTIC_DETAILS>
              <UDX.EDXF.NETWEIGHT>0.1814368</UDX.EDXF.NETWEIGHT>
            </UDX.EDXF.PRODUCT_LOGISTIC_DETAILS>
            <UDX.EDXF.REACH>
              <UDX.EDXF.REACH.LISTDATE>2017-01-24</UDX.EDXF.REACH.LISTDATE>
              <UDX.EDXF.REACH.INFO>no data</UDX.EDXF.REACH.INFO>
            </UDX.EDXF.REACH>
          </USER_DEFINED_EXTENSIONS>
          <PRODUCT_LOGISTIC_DETAILS>
            <CUSTOMS_TARIFF_NUMBER>
              <CUSTOMS_NUMBER>85351000</CUSTOMS_NUMBER>
            </CUSTOMS_TARIFF_NUMBER>
            <COUNTRY_OF_ORIGIN>MX</COUNTRY_OF_ORIGIN>
          </PRODUCT_LOGISTIC_DETAILS>
        </PRODUCT>
      </T_NEW_CATALOG>
    </BMECAT>

1 个答案:

答案 0 :(得分:0)

你说你不想要

上的命名空间(联合国)声明
<BUYER xmlns="">

这意味着,您希望结果文档中的BUYER元素位于名称空间http://www.bmecat.org/bmecat/2005fd中。但源文档中的BUYER元素没有名称空间。因此,结果文档中的BUYER元素与源文档中的BUYER元素不同:它不是精确副本,因此您无法使用<xsl:copy-of>生成它。复制元素永远不会更改元素的名称(命名空间是名称的重要部分)。

要更改源文档中元素的命名空间,您需要使用以下内容:

<xsl:template match="*" mode="rename">
  <xsl:element name="{local-name()}" namespace="http://www.bmecat.org/bmecat/2005fd">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="#current"/>
  </xsl:element>
</xsl:template>