Convert attribute value into element

后端 未结 3 2138
星月不相逢
星月不相逢 2020-12-11 08:57

I\'m trying to transform this xml:


 
  nomX
  prenomX

        
相关标签:
3条回答
  • 2020-12-11 09:47

    I used your answer to find the right xsl:

    here is what i use:

    <xsl:template match="token">
            <xsl:element name="{@cle}">
                <xsl:apply-templates/>
            </xsl:element>
        </xsl:template>
    

    Thank a lot !

    0 讨论(0)
  • 2020-12-11 09:53

    This should do the trick:

    <xsl:template match="token">
      <xsl:element name="{@cle}">
        <xsl:apply-templates select="*|@*"/>
      </xsl:element>
    </xsl:template>
    

    for more info on xsl:element see: http://www.w3.org/TR/xslt#section-Creating-Elements-with-xsl:element

    you might want to add some xsl:if to check if there really is a @cle attribute, but otherwise this should work fine

    0 讨论(0)
  • 2020-12-11 09:55

    so xslt is the right way I think:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" encoding="UTF-8"
            indent="yes" />
        <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()" />
            </xsl:copy>
        </xsl:template>
        <xsl:template match="token">
            <xsl:element name="{@cle}">
                <xsl:apply-templates />
            </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题