Use XSLT to transform a child node but leave the rest intact

pranav

New Member
I have a XML where I only want to modify a specific section, and leave the rest intact, how can this be done? i.e I only want to modify the node AA2\[code\]<root> <parentHeader> </parentHeader> <body> <ChildAA> <AA1> <foo>bar</foo> <foo>bar2</foo> </AA1> <AA2> <foo>bar</foo> <foo>bar2</foo> </AA2> </ChildAA> <ChildBB> <BB1> <foo>bar</foo> <foo>bar2</foo> </BB1> <BB2> <foo>bar</foo> <foo>bar2</foo> </BB2> </ChildBB> </body></root>\[/code\]I have the following XSLT which only returns the modified section. How can I include everything else?\[code\]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <!-- Whenever you match any node or any attribute --> <xsl:template match="/*"> <xsl:apply-templates/> </xsl:template> <xsl:template match="AA2"> <RenamedAA2> <xsl:copy-of select="."/> </RenamedAA2> </xsl:template> <xsl:template match="text()"/></xsl:stylesheet>\[/code\]I am looking for something like this as result\[code\]<root> <parentHeader> </parentHeader> <body> <ChildAA> <AA1> <foo>bar</foo> <foo>bar2</foo> </AA1> <RenamedAA2> <foo>bar</foo> </RenamedAA2> <RenamedAA2> <foo>bar2</foo> </RenamedAA2> </ChildAA> <ChildBB> <BB1> <foo>bar</foo> <foo>bar2</foo> </BB1> <BB2> <foo>bar</foo> <foo>bar2</foo> </BB2> </ChildBB> </body></root>\[/code\]
 
Back
Top