2009-11-25 114 views
1

我有一个XML文档,我想通过XSLT重命名一些元素:XSLT重命名元素

<Assert @some attributes here> 
    <conent> 
    <And> 
     <formula> 
     <Atom> 
      <opr> 
... 

例如,我要重命名<opr><op>。我有以下XSLT:

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

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

当我调试XSLT它只是没有了“OPR”模板里面去,它就会通过第一个模板匹配。生成的输出与输入相同。谁可以帮我这个事?

+0

我确定这是问几天前? –

+0

您确实想要匹配所有属性,还是只想确保将所有属性都复制到新节点? –

+0

我只是想要复制每一个,只需将opr重命名为op – user180812

回答

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

    <xsl:template match="opr"> 
    <op> 
     <xsl:call-template name="YourNameHere"/> 
    </op> 
    </xsl:template> 

你可能仍然需要像<的xsl:模板匹配= “/”/>得到它去。

+0

不,它似乎仍然工作 – user180812

0

这是行不通的?

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