【问题标题】:XSL: Remove parent and add namespace prefixXSL:删除父级并添加命名空间前缀
【发布时间】:2013-08-15 09:50:38
【问题描述】:

我无法删除 xml 父元素,然后将命名空间添加到其他元素。

有人可以帮忙吗?

我有这个 XML

<DOutput>
    <xxxOut>
        <ES>
            <Error a="1" b="10" c="900" d="blabla"/>
        </ES>
    </xxxOut>
</DOutput>

我需要得到这个..

        <cc:xxxOut>
            <cc:ES>
                <cc:Error a="1" b="10" c="900" d="blabla"/>
            </cc:ES>
        </cc:xxxOut>

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    使用

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:cc="http://example.com/cc"
      version="1.0">
    
    <xsl:template match="@* | text() | comment() | processing-instruction()">
      <xsl:copy/>
    </xsl:template>
    
    
    <xsl:template match="*">
      <xsl:element name="cc:{local-name()}">
        <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
    </xsl:template>
    
    <xsl:template match="DOutput">
      <xsl:apply-templates/>
    </xsl:template>
    
    </xsl:stylesheet>
    

    【讨论】:

    • 非常感谢。运行良好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 2011-03-04
    相关资源
    最近更新 更多