元素的XML属性

时间:2018-08-11 19:10:37

标签: xml xslt xml-attribute

我需要将属性转换为元素,但是在xslt代码下可以执行此操作,但是子元素的属性与值一起在子元素标签内,但我希望子元素后的属性值不在子元素之内。

Xml:

<parent>
<child xml:lang="EN">Value</child>
</parent>

Xslt代码:

<xsl:template match="child/@*">
 <xsl:element name="{local-name()}">
 <xsl:value-of select="."/>
 </xsl:element>
 </xsl:template>

xslt之后:

<parent>
<child><lang>EN</lang>Value</child>
</parent>

但要求是:

<parent>
<child>Value</child>
<lang>EN</lang>
</parent>

1 个答案:

答案 0 :(得分:0)

<xsl:template match="parent">
       <xsl:element name="parent">
           <xsl:apply-templates select="child"/>
           <xsl:apply-templates select="child/@*"/>
       </xsl:element>
    </xsl:template>
    <xsl:template match="child/@*">
        <xsl:element name="lang">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="child">
        <xsl:element name="child">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
According to your given xml you can do like this.
相关问题