How to remove multiple root tags in XML using XSLT? -
my xml looks like:
<payusw2r> <g_employee1> .. . </g_employee1> </payusw2r> <payusw2r> <g_employee2> .. . </g_employee2> </payusw2r>
i want make formed xml follows:
<payusw2r> <g_employee1> .. . </g_employee1> <g_employee2> .. . </g_employee2> </payusw2r>
basically want remove root tags < payusw2r >. can achieve using xslt? please provide here.
since xml input xslt needs well-formed, you'll have wrap instance in temporary root element. how depend on how you're running xslt. simple concatenating new start/end tags existing xml.
what should end this:
<temp> <payusw2r> <g_employee1> .. . </g_employee1> </payusw2r> <payusw2r> <g_employee2> .. . </g_employee2> </payusw2r> </temp>
then xslt this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/*"> <xsl:apply-templates select="*[1]"/> </xsl:template> <xsl:template match="/*/*[1]"> <xsl:copy> <xsl:copy-of select="@*|node()|following-sibling::*/*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
this result in output:
<payusw2r> <g_employee1> .. . </g_employee1> <g_employee2> .. . </g_employee2> </payusw2r>
Comments
Post a Comment