--------------------------------
Title
--------------------------------
Viewing Entries as XML
--------------------------------
Description
--------------------------------
To make the process of saving XML files of each entry a little easier, I thought I could create an XSL stylesheet that would output the XML of a single entry. I ended up using Marc Liyanage’s XML Pretty Printer template to create nicely indented XML files.
--------------------------------
Body
--------------------------------
Marc Liyanage created a useful application called TestXSLT. He also published an [XSLT template](http://www.entropy.ch/software/xsl/xml-prettyprinter.xslt) that helps to make XML output look pretty, that is, to be indented according to the hierarchical structure of the XML file.
I wasn’t happy with the output of the basic `` instruction. The formatting was looking a little weird. So, I remembered Marc’s work and went about seeing how his handy [XML Pretty Printer](http://www.entropy.ch/software/xsl/xml-prettyprinter.xslt) template might change things.
I created a page with a Parent Page of “Journal” and a URL Parameter of “entry” and ended up with something like this for the template body:
I made a very minor modification to Marc’s template to output tabs instead of two spaces for indents:
The tab character needed to be expressed as a [numeric character entity reference](http://www.w3.org/TR/html4/sgml/entities.html): ` `. For more information about white space handling in XML and XSLT, Dave Pawson has put together some [helpful resources](http://www.dpawson.co.uk/xsl/sect2/N8321.html#d12587e947). To view the XML for the current page, I can add some code to the entries template to output a link with the following signature:
{$root}/{$current-page}/xml/{$entry}/
For this to work on the Journal overview, I’ll need to use this instead:
XML
The unfortunate by-product of using XML Pretty Printer to format the XML is that the code blocks are stripped of all white space, turning them into a single line of code. I’ll have to think of a workaround for this.
--------------------------------
Date
--------------------------------
18 May 2009 8:59am
--------------------------------
Section
--------------------------------
Journal
--------------------------------
Category
--------------------------------
Technology
--------------------------------
Tags
--------------------------------
xslt