Re: pretty-printing XML
> > I'm looking for a way to nicely print out my XML data. > > I've looked at a few XSL stylesheets that claim to pretty-print XML, > > but they don't seem to do what I want. In particular, my XML has > > lots of very long comment lines, which I would like to be wrapped > > to a sensible line length, and indented with a hanging indent like this: > > > > <!-- blah blah > > blah blah > > blah blah --> Since people have different definitions of what constitutes "pretty", it will be difficult to know whether any tools meet your specific wrapping requirements without testing a bunch of them to see. This might be one of those cases where a clever Perl regexp is better than anything a pretty-printing parser would achieve. You might also experiment with different markup-aware text editors; some have wrapping features that may do what you want. Nevertheless, it is possible to devise a word-wrapping algorithm in pure XSLT, with hanging indents, even. It would be very slow and about 200 lines long, though. We used to use something like this to generate documentation, but I recently switched us to using an extension function that uses a Python 1-liner to do most of the work. You can see the monstrosity that we were using for word-wrapping here; maybe it will give you some ideas, even though it doesn't do the hanging indents (you can always wrap the text first, then recursively add the indents): http://cvs.4suite.org/cgi-bin/viewcvs.cgi/~checkout~/4Suite/Ft/Data/justify.xslt?rev=1.2 Note that it uses one of our own extension functions, f:split(), to split a string into a node-set. You can work around this with EXSLT str:split() or one of Dimitre's FXSL templates, as long as you use an RTF-to-node-set extension. Still a lot of work, though. Mike -- Mike J. Brown | http://skew.org/~mike/resume/ Denver, CO, USA | http://skew.org/xml/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format