Kirk Evans Blog

.NET From a Markup Perspective

Displaying XML data: defaultss.xslt

Displaying XML data: defaultss.xslt

  • Comments 3

As noted in yesterday's blog entry, I was looking for a means to "colorize" XML documents so that I could include XML within my blog.  I knew about Andrew Welch's XSLT version of defaultss.xslt, but that stylesheet did a little more than I wanted.  I simply wanted the generic color-coding capabilites for any XML document, but I didn't want JavaScript capabilities in the output.  Further, the styles had to be inlined (including the STYLE element in this RSS feed caused problems on several readers).  It removes the commented template rules of Andrew's stylesheet, inlines the styles, and removes the JavaScript capabilites. 

What I came up with still has some shortcomings.  XSLT cannot match the xmlns attribute of an element, it is up to the XSLT parser to include it in the output.  Without this capability, I cannot see a way to render the namespace declarations accurately.  Second, character entities are escaped into their HTML equivalent when the stylesheet is displayed.  When your HTML rendering requires "&lt;" to be visually rendered, it will be displayed with its character equivalent of "<".  A workaround is to escape the escape, using &amp;lt;. 

To download the stylesheet, see http://xmlandasp.net/examples/xslt/defaultss.xslt.

 

  • btw, there is a way to detect them (not pure xslt though) - look at Dimitre Novachev's XPathVisualizer tool[1] and particularly myDefaultss80.xsl stylesheet.

    [1] http://topxml.com/xpathvisualizer/
  • I didn't even think of looking at Dimitre's XPathVisualizer, great idea. I see that he is using the vxpathuser:xml() extension function for this very purpose... very resourceful. Thanks for the tip!

    BTW - anyone that has not seen Oleg's stuff (XInclude and nxsl.exe), you need to go rummage through the GotDotNet workspaces for awhile.
  • Hi Kirk and Oleg,

    Let me congratulate you for the very nice blogs you have, guys!

    Also, I'm really glad to see you two together in a project -- probably I should also find some free time to join you -- because I know it will be a pleasure.

    Now, on this concrete question -- yes, the XPath Visualizer (XPV) has been displaying XML in a nice way for 2.5 years.

    Yes, the stylesheets are not mine at all, but were adapted from the original authors (Jonathan Marsh (IE defaultss.sty) and Jonas Sicking (Mozilla's prettyprint.xslt).

    From these two, the XPV for Mozilla will display an xml document as well-formed -- it contains corrections to two problems typically present in xml prettyprinters.

    One of the fixed problems is that namespace definitions are deducted and generated in the displayed xml. Because this is done without any extension functions, sometimes the element on which the definition is generated may not be the one in the source. This is done more precisely in the XPV for IE, where an extension function is used to obtain the original source.

    The second problem is currently fixed only in the XPV for Mozilla. It happens so, that most xml prettyprinters will display

    <test>M &amp; M</test>

    as

    <test>M & M</test>


    To summarise: I'd reccomend the use of the stylesheet that comes with the XPV for Mozilla.

    Once again, thanks for the good job you guys are doing for the whole XML community!


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL

Page 1 of 1 (3 items)
Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
Translate This Page
Search
Archive
Archives