【问题标题】:Changing the element name and copying all attributes更改元素名称并复制所有属性
【发布时间】:2014-03-18 14:39:35
【问题描述】:

我有这个:

<tab:column align="left" class="notdecorated" label="lab"> <b>General Information</b> </tab:column>

我想得到这个:

<column align="left" class="notdecorated" label="lab"> <b>General Information</b> <column>

这是我的 -incomplete- xslt 转换器:

 <xsl:template match="tab:column">
    <column>
       <xsl:apply-templates />
    </column>
 </xsl:template>

它忽略“标签”部分但不复制属性。所以我像这样丰富了它:

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

但这也不起作用。 那么如何在复制属性的同时更改元素名称呢?

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    使用

     <xsl:template match="tab:column">
        <column>
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates />
        </column>
     </xsl:template>
    

    或身份转换模板加

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

    【讨论】:

    • 谢谢。 +1 快速回答,因为我在 xslt 上浪费了太多时间..
    • @Regenbogenfisch - 如果您需要,这里有更多关于身份转换的信息:w3.org/TR/xslt#copying
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多