将命名空间添加到嵌套元素

时间:2009-03-07 21:29:36

标签: xml xslt namespaces

我有一些类似的XML:

<envelope xmlns="http://test">
  <header>
    <msgId />
  </header>
  <body>
    <element1 />
  </body>
</envelope>

我想为<element1>节点添加一个名称空间。任何人都可以帮我解决如何使用XSLT做到这一点吗?

2 个答案:

答案 0 :(得分:1)

<xsl:template match="element1">
    <xsl:element name="element1" namespace="http:..."/>
</xsl:template>

答案 1 :(得分:1)

将属性值模板与name()

一起使用
<xsl:template match="element1">
  <xsl:element name="{name()}" namespace="http://other-namespace">
  …

带身份转换会给你

<envelope xmlns="http:\\test">
  <header>
    <msgId/>
  </header>
  <body>
    <element1 xmlns="http://other-namespace"/>
    …
相关问题