具有元素名称更改和值的XSLT转换

时间:2016-07-04 09:30:58

标签: xml xslt

帮助帮助从

使用XSLT转换XML
<Res> <body> <element>VERSION=0:1:1</element> <element>CLASS=2:1:1</element> <element>FUN=1:1:1</element> <element>ORG=0:1:1</element> <element>ID.002=4214980010224084:1:1</element> </body> </Res> 

输出:

<Res> <body> <VERSION>0:1:1</VERSION> <CLASS>2:1:1</CLASS> <FUN>1:1:1</FUN> <ORG>0:1:1</ORG> <ID.002>4214980010224084:1:1</ID.002> </body> </Res> 

1 个答案:

答案 0 :(得分:1)

以下是快速回答:

<xsl:stylesheet 
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/"> 
<Res>
<body>
<xsl:for-each select="Res/body/*">
<xsl:element name="{substring-before(., '=')}">
<xsl:value-of select="substring-after(.,'=')"/>
</xsl:element>
</xsl:for-each>
</body>
</Res>
</xsl:template> 
</xsl:stylesheet>

并产生以下输出:

<Res>
    <body>
        <VERSION>0:1:1</VERSION>
        <CLASS>2:1:1</CLASS>
        <FUN>1:1:1</FUN>
        <ORG>0:1:1</ORG>
        <ID.002>4214980010224084:1:1</ID.002>
    </body>
</Res>