我遇到以下问题。
我有这个XML
<?xml version="1.0"?>
<root>
<first>a</first>
<third>
<goal>b</goal>
</third>
</root>
我需要这种布局
<?xml version="1.0"?>
<root>
<first>a</first>
<second>
<goal>b</goal>
</second>
</root>
所以我认为XSLT对我来说是正确的工具,但我无法使其正常工作。
那就是我的XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root/third/goal">
<goal><xsl:value-of select="."/></goal>
</xsl:template>
</xsl:stylesheet>
任何帮助都将受到欢迎:-)
如果要更改third
元素,则需要编写一个模板来执行此操作:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root/third[goal]">
<second>
<xsl:apply-templates/>
</second>
</xsl:template>
</xsl:stylesheet>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句