XSLT Resource Page

Some useful links and info assembled by Joe Orr - Under Construction, of course. When I add some nice formatting and design to this page, you'll know I've run out of useful updates. Last update 11/12/00.


What...

eXtensible Stylesheet Language for Transformations

What is XSLT?

Some other definitions:

Why...

XSLT allows you to very easily transform XML into some other form such as:

This allows you for example, to completely separate content and form. You have your content in XML. You put the presentation into XSL. Simply by changing your XSL you can now:

Examples:

Running these examples on Windows NT/2000 (may work on 95/98, but don't count on it): One easy way is to use Instant Saxon, like this:

  1. Create a folder, for example C:\XSL.
  2. Unzip saxon.exe to C:\XSL (saxon.exe is inside this zip file).
  3. Open up a console (Command Prompt).
  4. Download the example XML and XSL files to C:\XSL
  5. Generate the result HTML from the XML and XSL inputs by using the following command:
    saxon -o output.htm source.xml style.xsl

You may find it helpful to first view the XSL and XML files in IE4+ first, since IE4+ allows you to look at these in tree view.

Some very simple examples:

# XML File XSL File Result HTML Example of : Comments
1 items.xml simple.xsl result1.htm template match="/"
for-each
value-of
 
2 items.xml simple2.xsl result2.htm if
normalize-space( )

The normalize-space function removes leading and trailing whitespace.

3 items.xml simple3.xsl result3.htm choose
when
otherwise
 
4 items.xml simple4.xsl result4.htm template The for-each has been removed, and instead we tell the XSL processor to apply-templates.
5 items.xml simple5.xsl result5.htm template The "msg" template has to be added to prevent the text of the "msg" element being output as it is in result4.htm.
6 items.xml simple6.xsl result6.htm output='xml'

This stylesheet has a <br /> element and a &#160; entity and these both get passed unchanged to the output, because the output tag has a method='xml' attribute.

7 items.xml simple7.xsl result7.htm output='html' In the output from this stylesheet, the <br /> has been converted to <br> and the &#160; has been converted to &nbsp;

 

A more developed example:

XML  XSL  Result  PNG files (unzip to same folder as result HTML).

A stylesheet that converts XML to a DHTML (IE 4+) representation of the XML:

The original XML file.
The stylesheet (this stylesheet is included with Xalan - get the latest version of Xalan for the latest version of this stylesheet.)
The output.


Examples that implement particular functionalities:

Example XML File XSL File Result HTML Comments

Data Island

items.xml
data_island.xsl data_island.htm

A "data island" is a chunk of XML inside your XSL stylesheet. You can access and use this XML with the syntax shown in this stylesheet. This may not work in some enviroments (e.g. Dynamo JHTML).

The input XML file doesn't actually get used by the example XSL.

Multiple XML sources transformed by a single XSL

Coming Soon      

Java Extensions

Coming Soon      

MSXML3's <eval> tag

Coming Soon      

Recursion

items2.xml table.xsl table.htm This stylesheet takes a list (i.e. one column) of xml elements and prints out an html table. You can change the number of columns by changing a parameter.

Recursion Example #2

Coming
Soon
     

 

Reference and Texts

XSL Processors:

One easy way to get started experimenting with XML - XSL transformations on Windows is to download the Instant Saxon processor. Unzip and run it from the command line with the following syntax:

saxon -o output.htm source.xml style.xsl

See above (Samples section) for more info about using Instant Saxon.


You can also run the Xalan processor from the command line:


Tools:

Other outputs besides HTML:


webmaster

Receive email when this page changes

Powered by NetMind
 
Click Here