高手们请进,在线等候

kongxx
博客专家认证
2003-05-15 01:57:01
我有一个这样的节点:

<node name="111" value="222" caption="333">
<child1></child1>
<child2></child2>
<child3></child3>
</node>

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

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

就是去掉子节点,然后将属性节点复制保留到另外一个节点下,但属性节点有可能会变.
...全文
72 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
月光易水 2003-05-15
  • 打赏
  • 举报
回复
a.xml
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="a.xsl"?>
<root>
<node name="111" value="222" caption="333">
<child1></child1>
<child2></child2>
<child3></child3>
</node>
<node myname="444" myvalue="555" mycaption="666">
<child1>1</child1>
<child2>2</child2>
<child3>3</child3>
</node>
</root>

a.xsl
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
<xsl:element name="root">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="node">
<xsl:element name="othernode">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</xsl:element>
</xsl:template>

</xsl:stylesheet>



:_)

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧