Re: [xsl] embedded stylesheets (long post contains code)

Subject: Re: [xsl] embedded stylesheets (long post contains code)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Jan 2002 18:28:49 +0000
Hi Chris,

> I'm trying to distribute a self-contained stylesheet to format and
> display data on MS IE 5.5 and higher browsers. (I have to send a
> single file with an .xml extension)

I don't think that you can use embedded stylesheets with IE (or I've
never yet managed to). However, what you can do is embed the *data*
within the *stylesheet* and then get at it using the document()
function.

A very quick example to demonstrate the idea. Here's "test.xml" - a
file that references itself as its own stylesheet. The source data is
embedded within the stylesheet, within the my:data element.

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xml"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:my="http://www.jenitennison.com/";
                exclude-result-prefixes="my">

<my:data>
  Foo bar
</my:data>

<xsl:template match="/">
  <html>
    <head><title>Test</title></head>
    <body>
      <h1>Here's my heading</h1>
      <xsl:value-of select="document('')/*/my:data" />
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

[Note that the my:data element has to be an element in a namespace;
you can stop this namespace from being added to the output using the
exclude-result-prefixes attribute as shown above.]

The result (tested in IE 6.0) is the HTML page:

<html>
  <head>
    <title>Test</title>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-16">
  </head>
  <body>
    <h1>Here's my heading</h1>
    Foo bar
  </body>
</html>

Out of interest, why do you need to deliver a single document rather
than two?

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread