【问题标题】:Adding a namespace to a nested element将命名空间添加到嵌套元素
【发布时间】:2009-03-07 21:29:36
【问题描述】:

我有一些类似的 XML:

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

我想向&lt;element1&gt; 节点添加一个命名空间。谁能帮助我如何使用 XSLT 做到这一点?

【问题讨论】:

  • 嗨,我有一个类似于这个的xml
    我想将命名空间添加到节点 。谁能帮助我如何使用 xslt 谢谢

标签: xml xslt namespaces


【解决方案1】:
<xsl:template match="element1">
    <xsl:element name="element1" namespace="http:..."/>
</xsl:template>

【讨论】:

    【解决方案2】:

    通过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"/>
        …
    

    【讨论】:

      猜你喜欢
      • 2019-11-17
      • 2017-11-27
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 2010-09-13
      相关资源
      最近更新 更多