在 .xsl 样式表的帮助下转换 xml 文件期间重命名子节点时遇到问题。问题是,只处理值而不是标签。我想两者兼得。
改造前原件:
<old>
<ns2:Header>
<EntityId>yxc</EntityId>
<Application>11</Application>
<Version>354</Version>
<User>
<Id>user1</Id>
</User>
</ns2:Header>
....
</old>
预期结果:
<new>
<Header>
<EntityId>yxc</EntityId>
<Application>11</Application>
<Version>354</Version>
<User>
<Id>user1</Id>
</User>
</Header>
...
</new>
到目前为止,我得到的是这样的 .xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<new xmlns:ns2="http://example.com">
<xsl:template match="//ns2:Header">
<xsl:element name="Header">
<xsl:apply-templates select="//ns2:Header" />
</xsl:element>
</xsl:template>
.....
</new>
</xsl:template>
</xsl:stylesheet>
转换后,“Header”的子节点丢失,只有值仍然存在:
<new xmlns:ns2="http://example">
<Header>
yxc
11
354
user1
</Header>
...
</new>
我想我错过了“应用模板”功能的一些表达。有任何想法吗?
谢谢!