我有以下XMLXSLT删除节点和atrribute值转换为元素名称
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="somename">
<node1></node1>
<node2></node2>
</lst>
<result name="somename" count="5">
<doc>
<str name="NodeA">ValueA</str>
<str name="NodeB">ValueB</str>
<str name="NodeC">ValueC</str>
</doc>
<doc>
<str name="NodeA">ValueD</str>
<str name="NodeB">ValueE</str>
<str name="NodeC">ValueF</str>
</doc>
</result>
</response>
,我要转换为
<?xml version="1.0" encoding="UTF-8"?>
<response>
<doc>
<NodeA>ValueA</NodeA>
<NodeB>ValueB</NodeB>
<NodeC>ValueC</NodeC>
</doc>
<doc>
<NodeA>ValueD</NodeA>
<NodeB>ValueE</NodeB>
<NodeC>ValueF</NodeC>
</doc>
</response>
正如你所看到的LST节点被完全去除,并属性值现在成为节点。
首先,我用这个xslt代码去除了第一个节点。
<?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" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="lst"/>
</xsl:stylesheet>
这给了我这个
<?xml version="1.0" encoding="UTF-8"?>
<response>
<result name="somename" count="5">
<doc>
<str name="NodeA">ValueA</str>
<str name="NodeB">ValueB</str>
<str name="NodeC">ValueC</str>
</doc>
<doc>
<str name="NodeA">ValueD</str>
<str name="NodeB">ValueE</str>
<str name="NodeC">ValueF</str>
</doc>
</result>
</response>
然后用这个XSLT从链接[link] Convert attribute value into element
<?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" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="response/result/doc">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="token">
<xsl:element name="{@name}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
但它并没有帮助。它给了我这个。
<?xml version="1.0" encoding="utf-8"?>
<doc>ValueAValueBValueC</doc>
<doc>ValueDValueEValueF</doc>
请帮我把属性值转换成节点的第二部分。 是否有可能让一个xslt做这两件事?
问题是什么/你在哪里卡住了? – 2013-03-15 14:00:22
您可以展示迄今为止获得的XSLT,因此我们可以看到/指出问题到底是什么? – 2013-03-15 14:03:27
发布更新。请检查。 – user1677271 2013-03-15 14:14:10