Re: [xsl] XSL stylesheet embedding for all browsers

Subject: Re: [xsl] XSL stylesheet embedding for all browsers
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Tue, 23 Aug 2011 15:08:17 +0200

I really like the solution of Valery 
(which basically is an enhancement to Jeni's posting from 2002).
This is pure XSLT, works for all big5 browsers and has no restrictions.

My own solution "[xsl] support of stylesheet embedding for ALL browsers"
had the drawback of document() function problems.

For an internal embedded stylesheet application I dropped support for 
IE because I needed document() for accessing previous documents for 
providing a history view. Changing to Valerie's method took only few 
lines of change and now everything is fine.

If you look into PageSource for Valery's 2nd example

you will notice that it contains (but not uses) David Carlisle's 
exslt:node-set implementation. Therefore it can be taken as template
for new stylesheets providing cross-browser XSLT 1.0+ (that is 
XSLT 1.0 plus exslt:node-set function).

Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
Fixpack team lead
WebSphere DataPower SOA Appliances
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294 

"Valery Chernysh" <spy00000@xxxxxxxxx>
08/17/2011 10:14 AM
[xsl] XSL stylesheet embedding for all browsers


I'd like  to show you some technique to place XML data and XSLT stylesheet
in one file so, that transformation work in all browsers, which support 
transformation (Internet Explorer, FireFox, Chrome, Safari, Opera).

As we know, there is a standard way to embed xslt stylesheet in xml files,
described in "XSL Transformations (XSLT) Version 1.0" specification in
paragraph 2.7 "Embedding Stylesheets"
(, and this does 
work in Internet Explorer (including version 9). Jeni Tennison  in her 

5/msg00146.html) describes the way for IE to embed the XML data within a
XSLT stylesheet. This is a very interesting method and in fact it works 
only in IE, but in other browsers (FireFox, Chrome, Safari, Opera). And
also, this method can be slightly modified for better using.

There is an inconvenience in this method  that in processing instruction 
href attribute we need to specify file name, and if file name does not 
name in PI (for example, if someone change name of the file, while 
then transformation stops working. I performed some experiments and found
that if the file extension is .xml, not .xsl (it's important for IE) and
specify PI in form of <?xml-stylesheet type="text/xsl" href="#"?> (without
any symbols between # and "), then XSLT stylesheet for transformation will
be expected in root node of XML document, and transformation will work in
all browsers. So for using XSLT stylesheet embedded in XML file we can use
next file structure:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="#"?>

<xsl:stylesheet version="1.0" 
      <!-- place for data -->

  <xsl:template match="/xsl:stylesheet">
    <xsl:apply-templates select="data:data/*" />

  <xsl:template match="doc">


I would like to thank Hermann Stamm-Wilbrandt for his help and for his
example of using <xsl:variable> to reduce the path to data node (you can 
this example in file supportALL.xml).

Example 1:
Example 2:

A few comments on referencing to XSLT stylesheet from processing

1. For referencing to XSLT stylesheet we can use standard way from XSLT
specification (with id="idstr" attribute in <xsl:stylesheet> and
href="#idstr" in PI), but this works in all browsers except Safari. As I
understand from my experiments, in files with embed stylesheet Safari 
<xsl:stylesheet> node used for transformation, and it is impossible to
utilize  the data placed inside <xsl:stylesheet> in Safari.

2. In IE referencing to XSLT stylesheet in form href="#style1" and 
works in the files with the .xml extension, and does not work in .xsl 
In other browsers such reference works both in .xml and .xsl files.

with best regards
Valery Chernysh

Current Thread