Linkwerk Logo

xml2html.xslt

Rendering of arbitrary XML in (X)HTML - Why and what for?

Open Source logo The motivation to write xml2html.xslt was the need to display XML code as part of a web site (guess which site? ;-). Since general XML markup uses the same special characters as HTML, the first approach is to escape those characters (i.e. &,<,>, etc.). But if you want a pretty syntax coloured version of your XML code, that's not enough. Therefore I wrote xml2html.xslt.

xml2html.xslt is a small program, written (of course) in XSLT, to transform arbitrary XML to XHTML. The result is easy customizable in terms of colouring, choosing fonts, etc. All of those styling is done with CSS.

"How does it work?"

  1. Get the software, xml2html.xslt. Read the licence information first and decide if you want to use this piece of software.

  2. Let your favourite XSLT engine (such as Xalan, Saxon, xsltproc, ...) run with xml2html.xslt as the stylesheet and your XML instance as the input data.

    You can control the output with the stylesheet parameter htmloutput. The default is to produce an entire HTML instance (with html, head, body elements). If you set htmloutput to short you'll get just a div element for inclusion in your own HTML files.

    If you don't like your XSLT comments printed in the XHTML output, set the parameter comments to drop (default is show).

"Right now I don't have an XML file, but I'd like to test it anyway!?" - First example

As soon as you downloaded xml2html.xslt you do have an XML file. Since XSLT is written with XML syntax, you can use xml2html.xslt to generate an HTML rendering of any XSLT program. For my stylesheet itself the result is available in the file xml2html.html.

"How do I customize the colouring, fonts, etc.?"

Get my default CSS stylesheet and modify it as you like.

You can easily include the generated HTML code in your own web pages. My CSS is designed to not interfere with your own CSS.

Advanced features

What are the common XML vocabularies you might want to display in (X)HTML? Certainly XHTML itself, XSLT, maybe SVG and some more. For those widely used XML vocabularies I added the feature to link from the XHTML rendering of an XML element to the specification of the corresponding element type. Sounds complicated? Check the XHTML rendering of xml2html.xslt and point your mouse over an XSLT element. As you will see, the start tag of each element is linked to the XSLT 1.0 specification. I'd like to add more linking of this kind.

To facilitate this it is required to be able to compute the URL from the element name. Fortunately this works for XSLT 1.0 and EXSLT.org. Unfortunately it does not work for the (X)HTML* and SVG specifications. Maybe I missed something. If you have ideas for improvements of xml2html.xslt, please let me know.

Version Information

Both files, XSLT and CSS, contain a Revision number and Time stamp. Major changes will be announced in our News.

History

$Revision: 1.7 $ $Date: 2006/10/19 11:47:31 $
Added xslt:output. Set output method to xml and media-type to text/html.

Stefan Mintert, $Date: 2006/10/19 11:54:00 $

Valid XHTML 1.0!