[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: pretty-printing XML

Subject: Re: pretty-printing XML
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 26 Mar 2003 14:54:06 -0700 (MST)
perl pretty print 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.