X hits on this document





50 / 142

Transforming XML with XSLT

Exercise - Transform an XML document with an XSLT stylesheet

In this exercise you will transform an XML document using XSLT.

  • 1.

    Create a directory on your computer's desktop.

  • 2.

    Copy all the *.dll files from the CD to your newly created directory.

  • 3.

    Copy all the *.exe files from the CD to your newly created directory.

  • 4.

    Copy cimi2html.xsl and water.xml from the CD to your newly created directory.

  • 5.

    Open a new terminal window by running cmd.exe from the Start menu's Run command.

  • 6.

    Change directories to your newly created directory.

  • 7.

    Transform the XML document into an HTML document using this command: xsltproc -o wa-

ter.html cimi2html.xsl water.xml .

  • 8.

    Open the newly created file named water.html in your Web browser.

  • 9.

    In this part of the exercise you will change the content of the output.

  • 10.

    Open cimi2html.xsl in your text editor.

  • 11.

    Add a signature as a footer; insert <p> Brought to you by [yourname]. </p> after the </ol> element

of the XSLT file.

  • 12.

    Process the XML again: xsltproc -o water.html cimi2html.xsl water.xml .

  • 13.

    Open and/or reload the output, water.html, in your browser.


Go to Step #2 and make some other changes until you get tired.

Displaying tabular data

Here is an other example of an XSLT file used to render an XML file. This example renders our cata- log.xml file. It too functions very much like a plain o' CSS file. You can transform it using xsltproc like this: xsltproc -o catalog.html catalog2html.xsl catalog.xml .

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- catalog2html.xsl -->

<xsl:output method="xml" omit-xml-declaration="no" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />


Document info
Document views608
Page views614
Page last viewedMon Jan 23 17:35:19 UTC 2017