File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Preserve comments in the XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Preserve comments in the XSL" Watch "Preserve comments in the XSL" New topic

Preserve comments in the XSL

Nira Shavitt

Joined: Jul 26, 2004
Posts: 19

I'm using xsl for a transformer to write a a DOM to a file, and I'm getting a problem - it eliminates the comments. Does anyone know how to reserve them?

This is the transformer I have:

private static final String TRANSFORMER_STRING = "<?xml version=\"1.0\"?>" +
"<xsl:stylesheet xmlns:xsl=\"\" xmlns:fo=\"\" xmlns:html=\"\" version=\"1.0\" stlptimize=\"true\" stl:version=\"0.6\">" +
"<xslutput encoding=\"ISO-8859-1\" method=\"xml\" indent=\"no\"/>" +
"<xsl:template match=\"*|@*\">" +
"<xsl:copy>" +
"<xsl:apply-templates select=\"*|@*|text()\"/>" +
"</xsl:copy>" +
"</xsl:template>" +
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Stripped of all the junk required to make it into a Java string, here's what you are matching:So, you aren't matching comments. And since the built-in processing rule for processing comments is to do nothing, they do not get copied to the output. To change that to match comments as well, do this:You might have to change your xsl:apply-templates element as well.
I agree. Here's the link:
subject: Preserve comments in the XSL
It's not a secret anymore!