DigitalMC
DigitalMC

Reputation: 877

Maintain HTML comments in XSLT

Basically I have HTML comments in my XSLT that I want to preserve in the output but XSLT keeps dropping them. They are totally removed. Any way to keep these comments?

Below is a code example:

<xsl:template match="/">

   <!-- Preserve This HTML Comment In Output -->
   <div><xsl:value-of select="xmlnode" /></div>

</xsl:template>

I've tried wrapping in <xsl:text> and <xsl:comment> tags but no help.

Upvotes: 1

Views: 908

Answers (1)

hr_117
hr_117

Reputation: 9627

You can't preserve comment but you can generate them in output with:

  <xsl:comment>This is a comment!</xsl:comment> 

Therefor try

<xsl:template match="/">
   <!-- Preserve This HTML Comment In Output -->
  <xsl:comment>Preserve This HTML Comment In Output</xsl:comment> 
  <div><xsl:value-of select="xmlnode" /></div>
</xsl:template>

Upvotes: 3

Related Questions