<h:body>
<group id = "1">
<name>xxx</name>
<age>12</age>
<group id = "2">
<name>yyy</name>
<age>13</age>
</h:body>
使用XSLT我想用<group appearance = "field-list">
答案 0 :(得分:1)
使用identity transform,用不同的东西覆盖您要替换的部分。即:
鉴于此输入XML文档:
<h:body xmlns:h="http://example.org/h">
<group id = "1">
<name>xxx</name>
<age>12</age>
</group>
<group id = "2">
<name>yyy</name>
<age>13</age>
</group>
</h:body>
此XSLT转换:
<xsl:stylesheet version="1.0"
xmlns:h="http://example.org/h"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="group[@id = '1']">
<group appearance = "field-list">
<xsl:apply-templates select="node()|@*"/>
</group>
</xsl:template>
</xsl:stylesheet>
将生成此输出XML文档:
<h:body xmlns:h="http://example.org/h">
<group appearance="field-list" id="1">
<name>xxx</name>
<age>12</age>
</group>
<group id="2">
<name>yyy</name>
<age>13</age>
</group>
</h:body>