Yliopiston etusivulle Suomeksi
Helsingin yliopisto
clt232: Rakenteisten dokumenttien käsittely (Structured Documents Processing) - syksy 2006

Yhteystiedot

Yleisen kielitieteen laitos
PL 9 (Siltavuorenpenger 20 A)
00014 Helsingin yliopisto

Puhelinvaihde +358 (09) 1911
Faksi +358 (09) 191 29307

9. XSLT (XSL Transformations).

  • Lecture notes
  • Further reading
  • Practical work: Xalan and Emacs on venus
    • On Windows, start XSession and login to venus via Putty (make sure "Enable X11 forwarding" is ticked in Putty configuration).
    • Copy the shell script clt232-xalan to your directory.
      Make it executable (chmod +x clt232-xalan).
      This script runs the open source Xalan Java XSLT transformer.
    • On venus, use GNU Emacs (via XSession) to edit XML files and XSLT stylesheets. Use the Xalan script (via Putty) to do XSLT transformations. Check the HTML output files in a web browser and in a text editor.
    • "Hello, World": Copy hello.xml, hello.xsl to your directory.
      Transform the XML file to HTML with the stylesheet by
      ./clt232-xalan -in hello.xml -xsl hello.xsl -out hello.html
    • Empty stylesheet: Copy empty.xsl to your directory.
      Transform the XML file to HTML with the empty stylesheet by
      ./clt232-xalan -in hello.xml -xsl empty.xsl -out empty.html
    • XSLT Tutorial (only "XSLT Basic"): Copy cdcatalog.xml and stylesheets cdex1.xsl, cdex2.xsl, cdfor.xsl, cdfilter.xsl, cdsort.xsl, cdif.xsl, cdchoose.xsl.
      Transform cdcatalog.xml with all the stylesheets like this (example 1):
      ./clt232-xalan -in cdcatalog.xml -xsl cdex1.xsl -out cdcatalog.html

10. XPath and XSLT. Transforming XML to XHTML.

  • Lecture notes
    • XPath from XML in a Nutshell by Harold & Means (O'Reilly)
  • Further reading
  • Practical work: XSLT and XPath in jEdit
    • On Windows, use jEdit to edit XML files and XSLT stylesheets. Use jEdit's XSLT plugin to run Xalan Java inside jEdit to do XSLT transformations.
    • On Windows, start jEdit and open Plugins -> Plugin Manager -> Install tab. In the Install tab, tick XSLT then click the Install button to install it.
    • The XSLT plugin includes XPath Tool and XSLT Processor. Use jEdit's menus to open them. Use the docking options to dock XPath Tool on the right and to dock XSLT Processor on the bottom.
    • Copy the files hello.xml, hello.xsl, empty.xsl again, this time to your temporary Windows folder. Open hello.xml in jEdit and use jEdit's XSLT plugin to do the XSLT transformations again (inside jEdit) using the two stylesheets.
    • Copy cdcatalog.xml and the example stylesheets again, this time to your temporary Windows folder. Open cdcatalog.xml in jEdit and use the XSLT plugin to do the XSLT transformations again inside jEdit.
    • In jEdit we can use the XPath plugin to check which parts of an XML document are selected by different XPath expressions. We can do this without actually doing any XSLT transformations.
    • Copy the XPath examples 9-1.xml, 9-2.xsl, 9-3.xsl, 9-4.xsl to your temporary Windows folder. In jEdit, use the XPath plugin to check which parts of 9-1.xml are selected by the various XPath expressions included in the stylesheets.
    • Then use the XSLT plugin to do the transformations, and check the results.
  • Practical work: Xalan and Emacs on venus (continued)
    • Copy the XPath examples 9-1.xml, 9-2.xsl, 9-3.xsl, 9-4.xsl to your directory.
      Do the transformations with the example stylesheets, for example:
      ./clt232-xalan -in 9-1.xml -xsl 9-2.xsl -out 9-2.html
    • Copy sonnet130.xml, sonnet.dtd, sonnet-html.xsl to your directory.
      Validate the sonnet against the DTD (same as last week) by
      ./clt232-xerces -v sonnet130.xml
    • Transform the sonnet from XML to HTML with the stylesheet by
      ./clt232-xalan -in sonnet130.xml -xsl sonnet-html.xsl -out sonnet130.html
    • Copy another of Shakespeare's sonnets (or compose your own sonnet).
      Edit it to create the same XML format, validate it with the same DTD, and transform it to HTML with the same XSLT stylesheet.

Assignment 4.

© 2001-2006 Graham Wilcock