[Snapshot 1999-07-26. Get the canonical/updated version: http://www.sci.kun.nl/sigma/Persoonlijk/egonw/xslt/.]


 
  • Supported commands
  • Action!
  • Script options
  • Download
  • Bugs
  • What's Next
  • Links
  • Send comment and bugs to:

    Geert Josten and
    Egon Willighagen

    last modified on 23rd July.


    XSA doc: xslt-parser.xsa.

    XML::XSLT (to be) Homepage

    XSLT

    You wrote some XML, and have a XSL Template. You want to use this on your website, but want to use Perl with your webserver. No Problem!

    XML::XSLT will convert the XML doc on basis of the template. It is written in Perl and works. However, at this moment it is not yet a module, but a script. Neither are all xsl command implemented. Nor is it fast. But in the meanwhile still it works: watch it in action.

    At this moment we need a lot of input. So try this script and give us your comment on it. Missing/needed xsl elements, bugs, anything...

    This document gives some explanation on this project. Other Stuff to read is the Working Draft on XSLT and the XSL(T)-by-example page (see links).

    Below, given is a list of XSLT-command's that are supported.

    Supported XSLT commands

    At this moment the xslt-parser commands are out of focus with the XSL-T draft. The stylesheet files it accepts are not even valid XML conform the XSL Working Draft. At this moment at least.

    Each element the script encounters that doesn't start with xsl: (or are in the xsl namespace) are regarded to be markup and handled as is. This leads to some strange sheets like the CML2CML stylesheet furtheron, in which the first to lines (<?xml version... and <?xml-stylesheet...) are not xml declarations but simple markup.

    command supported comment
    xsl:stylesheet no not used as root, the script just starts at the first line of the xsl-file
    xsl:template yes  
    xsl:sub-template yes this implements nesting of template instead of the use of apply-templates
    xsl:apply-template no although obsolete with this new approach of nesting all template, we hope to support this command as well for compatibility reasons
    xsl:include yes  
    xsl:value-of yes attribute selection, element values. Examples:
    <xsl:value-of select="string"/> <html:url href="url[@href]">
    xsl:for-each yes  
    xsl:choose yes  
    xsl:when yes Example:
    <xsl:when test="@type='string'">
    xsl:otherwise yes buggy, i.e. if a xsl:when test was positive this test should be negative, but it isn't

    Action!

    Oke, let's see it work. The script takes a project name <project>. The files <project>.xml and <project>.xsl are read and converted to an internal object tree with XML::DOM. Then the XSL template is parsed against the XML tree, which results in a new doc that is redirected to STDOUT. That's all.

    Ofcourse, it need not be HTML. With XSLT you can convert any XML document with any XSL doc you like.

    This is the CML-project:

    • This project makes old CML files of the Dictionary on Organic Chemistry conform the newest CML DTD.
    • 91-22-5.cml (old cml file)
    • cml2cml.xsl (for cml to cml conversion)
    • resulting 91-22-5.xml
    • Please note that is you use IE 5.0 to view the result you it gets parsed by the IE XSL parser for a XML2HTML conversion due to the xsl stylesheet below. If so, use right mouse button and view source to see the underlying xml file when viewing the xml file with the stylesheet.
    • cml.xsl

    This is the Agenda-project:

    Script options

    The script can be used as an CGI script, but also as a command-line utility. Also accepts a XSL Template other than <project>.xsl. These behaviours are selected with some options. Run xslt-parser without options or parameters at the commandline to view its syntax.

    the -n option
    When a script is to be used with a web-server, its output must be preceeded with a Content-type line. The xslt-parser script does this by default. It can be turned off with the -n(oweb) option.

    the -s option
    By default the script uses the <project>.xsl XSLT template. With the -s(tylesheet) <template.xsl> option other templates can be used.

    Download

    Download version 0.1 of the script here. It requires the modules XML::Parser and XML::DOM which can be obtained from CPAN. A changelog is available.

    Bugs

    • xsl:otherwise bug
    • buggy implementation of xsl:value-of, i.e. it assumes that the element on which it is executed contains CDATA and not other elements.
    • buggy implementation of xsl:when, i.e. when it is encountered outside a xsl:choose element, and its test result a false, not all its children are skipped.

    What's Next?

    To do:

    • debugging ofcourse
    • xsl:stylesheet
    • better selection and match support
    • Making it a module (working on that one)
    • Better performance
    • and at the end full support of XSL-T Section 2

    Links

    XSL-T

    Other