高手们请进,在线等候

我有一个这样的节点:

1<node caption="333" name="111" value="222">
2<child1></child1>
3<child2></child2>
4<child3></child3>
5</node>

用xsl转换以后期望得到如下节点:

1<othernode caption="333" name="111" value="222"></othernode>

就是去掉子节点,然后将属性节点复制保留到另外一个节点下,但属性节点有可能会变.
---------------------------------------------------------------

a.xml

 1<root>
 2<node caption="333" name="111" value="222">
 3<child1></child1>
 4<child2></child2>
 5<child3></child3>
 6</node>
 7<node mycaption="666" myname="444" myvalue="555">
 8<child1>1</child1>
 9<child2>2</child2>
10<child3>3</child3>
11</node>
12</root>

a.xsl

 1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 2<xsl:template match="/">
 3<xsl:element name="root">
 4<xsl:apply-templates></xsl:apply-templates>
 5</xsl:element>
 6</xsl:template>
 7<xsl:template match="node">
 8<xsl:element name="othernode">
 9<xsl:for-each select="@*">
10<xsl:attribute name="{name()}">
11<xsl:value-of select="."></xsl:value-of>
12</xsl:attribute>
13</xsl:for-each>
14</xsl:element>
15</xsl:template>
16</xsl:stylesheet>

:_)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus