Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncomment XML content with XSLT

Tags:

xslt

I have a problem with XML and XSLT. I have one XML file with some comment and I want to uncomment it.

For example:

<my-app>
 <name>
 </name>
  <!-- <class>
         <line></line>
   </class>-->
</my-app>

I want to uncomment this commented tag.

like image 479
vivek4075 Avatar asked Dec 14 '22 00:12

vivek4075


1 Answers

<!-- the identity template copies everything 
     (unless more specific templates apply) -->
<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>

<!-- this template matches comments and uncomments them -->
<xsl:template match="comment()">
  <xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>

Be aware that disable-output-escaping="yes" implies that the comment contents should be well-formed.

like image 123
Tomalak Avatar answered Jan 24 '23 13:01

Tomalak