how to remove comments in xml without removing its text in xslt -
input file
<a> <b> <!--<docinfo:topiccodes><docinfo:topiccode>#pa#hkcrp#</docinfo:topiccode> <docinfo:topiccode>#pa#hkcrpm#</docinfo:topiccode><docinfo:topiccode>#pa#hkdis#</docinfo:topiccode><docinfo:topiccode>#pa#hkdism#</docinfo:topiccode><docinfo:topiccode>#pa#code#</docinfo:topiccode></docinfo:topiccodes>--> </b> </a>
output expexted
<a> <b> <docinfo:topiccodes><docinfo:topiccode>#pa#hkcrp#</docinfo:topiccode> <docinfo:topiccode>#pa#hkcrpm#</docinfo:topiccode><docinfo:topiccode>#pa#hkdis#</docinfo:topiccode><docinfo:topiccode>#pa#hkdism#</docinfo:topiccode><docinfo:topiccode>#pa#code#</docinfo:topiccode></docinfo:topiccodes> </b> </a>
xslt written
<xsl:template match="comment()"> <xsl:value-of select="."/> </xsl:template>
try this:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:strip-space elements="*"/> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="*|processing-instruction()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="comment()"> <xsl:value-of select="." disable-output-escaping="yes"></xsl:value-of> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment