Reputation: 11
<h:body>
<group id = "1">
<name>xxx</name>
<age>12</age>
<group id = "2">
<name>yyy</name>
<age>13</age>
</h:body>
using XSLT i want to replace id=1 with <group appearance = "field-list">
Upvotes: 0
Views: 64
Reputation: 111726
Use the identity transform, overriding the part you wish to replace with something different. To wit:
Given this input XML document:
<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>
This XSLT transformation:
<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>
Will produce this output XML document:
<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>
Upvotes: 1