xsl-list
[Top] [All Lists]

RE: [xsl] Using a TransformerHandler strips comments but a Transformer keeps them

2008-02-13 04:18:18
A SAX parser (XMLReader) doesn't notify comments to the ContentHandler, it
notifies them to the LexicalHandler. So you need to nominate the
TransformerHandler to the XMLReader in both roles: both as ContentHandler
and as LexicalHandler.

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Andrew Welch [mailto:andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com] 
Sent: 13 February 2008 10:54
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Using a TransformerHandler strips comments but 
a Transformer keeps them

Does anyone know why a transform using a TransformerHandler 
strips comments but the "stardard" Tranformer keeps them.

For example:

sourceXML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- test outer comment -->
<foo> <!-- inner comment --> foo</foo>

The stylesheet is the identity transform.

The first transformation technique is using a TransformerHandler:

SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInstance();;
TransformerHandler handler = stf.newTransformerHandler(new 
StreamSource(stylesheet)); handler.setResult(new 
StreamResult(System.out)); XMLReader xmlReader = 
XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(sourceXML.toURI().toString());

The second is using a Transformer:

stf.newTransformer(new StreamSource(stylesheet)).
              transform(new StreamSource(sourceXML), new 
StreamResult(System.out));

Produces this output:

TransformerHandler:
<?xml version="1.0" encoding="UTF-8"?><foo>  foo</foo>

Transformer:
<?xml version="1.0" encoding="UTF-8"?><!-- test outer comment --><foo>
<!-- inner comment --> foo</foo>


I would expect the two to produce identical results.  Has 
anyone come across this before?


thanks
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>