Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preserve comments in the XSL

 
Nira Shavitt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

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=\"http://www.w3.org/1999/XSL/Transform\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" xmlns:html=\"http://www.w3.org/TR/REC-html40\" 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>" +
"</xsl:stylesheet>";
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic