How to copy particular element in an XML using XSLT 1.0 -
first, let me provide sample xml guys clear after.
<a>1</a> <b>1</b> <c>1</c> <d>1</d> <e>1</e> <f>1</f>
is possible copy node b , e f. need neglect node c , d.
there <xsl:copy>
can copy elements, need particular element out of original xml.
thank you.
sure can remove needed elements. write empty templates on specified elements after identity transform.
source xml
<root> <a>1</a> <b>1</b> <c>1</c> <d>1</d> <e>1</e> <f>1</f> </root>
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- empty template remove elements --> <xsl:template match="c|d"/> </xsl:stylesheet>
output xml
<root> <a>1</a> <b>1</b> <e>1</e> <f>1</f> </root>
alternatively, select particular nodes keep:
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:strip-space elements="*"/> <!-- root template match --> <xsl:template match="root"> <xsl:copy> <xsl:apply-templates select="a|b|e|f"/> </xsl:copy> </xsl:template> <!-- select particular elements --> <xsl:template match="a|b|e|f"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment