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
Hello,

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"
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201002/msg00301.html
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
http://stamm-wilbrandt.de/en/xsl-list/Valery_Chernysh/supportALL.xml

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
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294 



From:
"Valery Chernysh" <spy00000@xxxxxxxxx>
To:
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Date:
08/17/2011 10:14 AM
Subject:
[xsl] XSL stylesheet embedding for all browsers



Hello!!!

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 
XSL
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"
(http://www.w3.org/TR/xslt#section-Embedding-Stylesheets), and this does 
not
work in Internet Explorer (including version 9). Jeni Tennison  in her 
post
(
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/20020

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 
not
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 
in
href attribute we need to specify file name, and if file name does not 
match
name in PI (for example, if someone change name of the file, while 
saving),
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" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:data="http://www.example.com/";>
  <data:data>
    <doc>
      <!-- place for data -->
    </doc>
  </data:data>

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

  <xsl:template match="doc">
  </xsl:template>

</xsl:stylesheet>

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 
see
this example in file supportALL.xml).

Example 1: http://stamm-wilbrandt.de/en/xsl-list/Valery_Chernysh/table.xml
Example 2:
http://stamm-wilbrandt.de/en/xsl-list/Valery_Chernysh/supportALL.xml

A few comments on referencing to XSLT stylesheet from processing
instruction.

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 
"hide"
<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 
href="#"
works in the files with the .xml extension, and does not work in .xsl 
files.
In other browsers such reference works both in .xml and .xsl files.


with best regards
Valery Chernysh
spy00000@xxxxxxxxx

Current Thread