我无法处理简单的XSLT转换。
存在一个扁平结构的输入XML:
<root>
<attribute_a>abc</attribute_a>
<attribute_b>def</attribute_b>
<attribute_c>ghi</attribute_c>
<attribute_a>123</attribute_a>
<attribute_b>456</attribute_b>
<attribute_c>789</attribute_c>
<attribute_a>xxx</attribute_a>
<attribute_b>xxx</attribute_b>
<attribute_c>xxx</attribute_c>
</root>
我应该将它转换为如下的XML格式:
<root>
<attribute>
<attribute_a>abc</attribute_a>
<attribute_b>def</attribute_b>
<attribute_c>ghi</attribute_c>
</attribute>
<attribute>
<attribute_a>123</attribute_a>
<attribute_b>456</attribute_b>
<attribute_c>789</attribute_c>
</attribute>
<attribute>
<attribute_a>xxx</attribute_a>
<attribute_b>xxx</attribute_b>
<attribute_c>xxx</attribute_c>
</attribute>
</root>
但问题是,像这样进行转换后:
<?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" indent="yes" />
<xsl:template match="/">
<root>
<xsl:for-each select="root/attribute_a">
<attribute>
<attribute_a>
<xsl:value-of select="../attribute_a" />
</attribute_a>
<attribute_b>
<xsl:value-of select="../attribute_b" />
</attribute_b>
<attribute_c>
<xsl:value-of select="../attribute_c" />
</attribute_c>
</attribute>
</xsl:for-each>
</root>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
我得到了类似这样的东西:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<attribute>
<attribute_a>abc</attribute_a>
<attribute_b>def</attribute_b>
<attribute_c>ghi</attribute_c>
</attribute>
<attribute>
<attribute_a>abc</attribute_a>
<attribute_b>def</attribute_b>
<attribute_c>ghi</attribute_c>
</attribute>
<attribute>
<attribute_a>abc</attribute_a>
<attribute_b>def</attribute_b>
<attribute_c>ghi</attribute_c>
</attribute>
</root>
我在XSLT方面经验不够 - 你有什么想法?:(
祝好, A. M.