xsl-list
[Top] [All Lists]

Re: [xsl] Wrong indentation with javax.xml.transform.Transformer

2011-09-21 05:33:22
Just an observation on pretty-printing issues:

If you, or users of your output, were using a virtual formatting
viewer or editor (which just extends the left-margin to indent) you
wouldn't care about the pretty print formatting characters. You would
simply view/edit the XML in the formatting style set in the virtual
formatter. The preference then would be to set the INDENT property of
transformer to "no", but otherwise the virtual formatter would remove
the pretty-print characters for you anyway to ensure the view (but not
the text) was properly formatted.

So far as preserving the integrity of the XML content goes: generally,
its safer to trim formatting characters than to add them. This is
because the pattern of leading whitespace characters can actually be
exploited by the trimming algorithm to ensure only pretty-print
whitespace is removed. Unless a schema can be exploited, a
pretty-printer doesn't have the equivalent information to prevent it
adding whitespace to unformatted XML where it shouldn't.

For this reason, I use code to ensure that the XSLT processor I use
never indents the XML output, even when xsl:output settings in the
XSLT request otherwise. The only thing the virtual formatter then does
to the XML is insert formatting line-feeds if required.

Phil Fearon
http://qutoric.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>
--~--