Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment in XSLT and not HTML

Tags:

comments

xslt

I'm writing XSL and I want to make comments throughout the code that will be stripped when it's processed, like PHP, however I'm not sure how.

I'm aware of the comment object, but it prints out an HTML comment when processed. :\

<xsl:comment>comment</xsl:comment> 
like image 384
Kirk Strobeck Avatar asked Dec 10 '10 15:12

Kirk Strobeck


People also ask

How do I comment code in XSLT?

The <xsl:comment> element is used to create a comment node in the result tree.

What is text () in XSLT?

XSLT <xsl:text> The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.

Can you use CSS with XSLT?

An XSLT style sheet can emit HTML <STYLE> elements, including CSS specifications, directly into the HTML that results from the XSLT transformation. This option works best when the number of CSS rules is small and easily managed.

How XML is converted into HTML format using XSLT?

The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.


2 Answers

Just make sure that you put your <!-- comments --> AFTER the opening XML declaration (if you use one, which you really don't need):

BREAKS:

<!-- a comment --> <?xml version="1.0"?> 

WORKS:

<?xml version="1.0"?> <!-- a comment --> 

I scratched my head on this same issue for a bit while debugging someone else's XSLT... seems obvious, but easily overlooked.

like image 34
Veloz Avatar answered Sep 22 '22 10:09

Veloz


You use standard XML comments:

<!-- Comment --> 

These are not processed by the XSLT transformer.

like image 62
Kathy Van Stone Avatar answered Sep 22 '22 10:09

Kathy Van Stone