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.
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
The default is to produce an entire HTML instance (with html, head, body elements).
If you set
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
drop (default is
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.
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.
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.
Both files, XSLT and CSS, contain a Revision number and Time stamp. Major changes will be announced in our News.