The Caboteria / Tech Web / XmlXslCssExperiment (01 Jan 2004, TobyCabot)
(TobyCabot - 12 Nov 2003)

We found out from the XmlCssExperiment that we can't expect to send XML and CSS to browsers and get good cross-browser results. Mozilla does a pretty good job, but IE doesn't. There's another approach, though: send an XML document with a link to an XSL stylesheet. The stylesheet transforms the XML document into HTML which the browsers seem to be better at displaying than raw XML.

Here's a document that includes a link to an XSL stylesheet:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="trivial.xsl" ?>
 This is an XML document.  It's well-formed but doesn't have a DTD so
 we can't say if it's valid or not.  It also has a processing
 instruction that tells the browser how to find an XSL stylesheet with
 instructions how to transform the document into HTML.

The xml-stylesheet processing instruction tells the browser where to look for the stylesheet, which is a little more complex (since XSLT is pretty complex):

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="">

 <xsl:template match="/">
 <!-- The overall structure of a page -->
    <title>Sample XML/XSL Page</title>

    <xsl:value-of select="body" />

 <xsl:template match="hidden" />

You can see the result here, it's pretty plain. We can spruce it up by adding a link to a CSS stylesheet, in this case using the same link that you'd use in a regular HTML page.

 <title>Sample XML/XSL/CSS Page</title>
 <link rel="stylesheet" type="text/css" href="trivial.css"/>

You can see the result here.

Edit | Attach | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Copyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding The Caboteria? Send feedback