xml - XSLT with XPath - Wrap children elements with new Parent -
input:
<s:e1 ...> <s:e2 ...> <s:child1 ...> <s:echild1 ...> ... </s:echild1 ...> </s:child1 ...> </s:e2> </s:e1 ...> desired output is:
<s:e1 ...> <s:e2 ...> <s:xyz> <s:child1 ...> <s:echild1 ...> ... </s:echild1 ...> </s:child1 ...> </s:xyz> </s:e2> </s:e1 ...> i.e, want wrap all children elements attributes , children of <s:e2> in <s:xyz>.
xslt came was:
<xsl:stylesheet version="2.0" ...> <xsl:output indent="yes"/> <xsl:template match="//*:e2"> <s:xyz> <xsl:apply-templates/> </s:xyz> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> this generating output <s:xyz> becomes <s:e2>, not direct child element.
try:
<!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*:e2"> <xsl:copy> <xyz> <xsl:apply-templates select="@*|node()"/> </xyz> </xsl:copy> </xsl:template>
Comments
Post a Comment