【问题标题】:Add Namespace to anonymous xml将命名空间添加到匿名 xml
【发布时间】:2017-01-24 12:13:00
【问题描述】:

我正在尝试将命名空间添加到输入:

<?xml version="1.0" encoding="utf-8"?>
<VLOG_Export>
  <Send_Referenznr_01>3200000042</Send_Referenznr_01>
  <Send_Referenznr_06>00000000001000189718</Send_Referenznr_06>
  <Send_ID>1Z78A1070461454103</Send_ID>
</VLOG_Export>

预期输出:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:VLOG_Export xmlns:ns0="http://mycomp.com/VLOG/SD/vlog/export">
   <Send_Referenznr_01>sdfsdf</Send_Referenznr_01>
   <Send_Referenznr_06>sdfsf</Send_Referenznr_06>
   <Send_ID>sdfsdf</Send_ID>
</ns0:VLOG_Export>

使用这个 xslt :

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="*" priority="1">
        <xsl:element name="{local-name()}" namespace="http://mycomp.com/VLOG/SD/vlog/export">
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

我得到了错误的输出。 欢迎任何提示。 谢谢

【问题讨论】:

    标签: xslt namespaces


    【解决方案1】:

    这按预期工作:

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:ns0="http://mycomp.com/VLOG/SD/vlog/export">
        <xsl:output indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="/VLOG_Export" priority="1">
            <xsl:element name="ns0:{local-name()}">
                <xsl:apply-templates select="@*|node()"/>
            </xsl:element>
        </xsl:template>
    
    </xsl:stylesheet>
    

    看看它是否正常工作:http://xsltransform.net/6rewNyz

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 2017-09-21
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多