【发布时间】:2016-06-19 05:19:44
【问题描述】:
我是 xslt 的新手。我试图用属性名称重命名我的 .xml 的元素名称,并删除该属性。
这是我要转换的 XML 示例:
<configdata>
<element xsi:type="AAA">
<attributes>
<att1>0</att1>
<att2>1</att2>
<att3>25</att3>
</attributes>
</element>
<element xsi:type="BBB">
<attributes>
<att4>23</att4>
<att5>44</att5>
<att6>12</att6>
</attributes>
</element>
</configdata>
想要的输出:
<configdata>
<AAA>
<attributes>
<att1>0</att1>
<att2>1</att2>
<att3>25</att3>
</attributes>
</AAA>
<BBB>
<attributes>
<att4>23</att4>
<att5>44</att5>
<att6>12</att6>
</attributes>
</BBB>
</configdata>
xml 包含数百个元素(AAA、BBB、CCC、DDD...),因此,任何通用解决方案都会很棒。
我已尝试使用以下 xslt 代码,但在输出中我保持输入 xml 不变。
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="element">
<xsl:element name="{@xsi:type}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我将不胜感激。谢谢
【问题讨论】: