The midterm is graded. If you didn't get yours back on Friday,
it's available from the TAs.
XSL has two parts: XSLT, which stands for XSL Transformations, and XSL-FO, which stands for XSL Formatting Objects. We'll only consider XSLT, which has many implementations, unlike XSL-FO.
To use XSL, you need an XSL engine. Internet Explorer 6 includes
one for XSLT version 1.0, and IE 5 and 5.5 partially implement an old draft
of XSLT. There are several XSL engines in Java and other languages
that you can download and install in your ieng9 account.
PHP can include an XSL engine known as Sablotron.
<?xml version="1.0"?>The stylesheet, that is the XSLT script, looks like
<?xml-stylesheet type = "text/xml" href = "http://ieng9.ucsd.edu/style.xsl"?>
...
<?xml version="1.0"?>The result of applying this stylesheet to a document with two <person> elements is
<xsl:stylesheet version="1.0"
xmlns:xsl = "http://www.w3.org/XSL/Transform">
<xsl:template match="person">A person.</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>The white space and new lines surrounding the text was carried over from the original XML document. Note that the output is not a well-formed XML document, despiet the automatically generated XML headerA Person
A Person
For each element that is processed in the pre-order, if a matching template exists, it is applied.
The element <xsl:template match="person">A person.</xsl:template> is an example of a template. It says to output the given text whenever an element with the name specified by match="person" is encountered.
Another example is
<xsl:template match="person">Note that stylesheets must be well-formed XML documents themselves, so the <p> tag must be followed by a closing </p> tag.
<p> Name: <xsl:value-of select = "name"/> </p>
</xsl:template>
The value-of an element is its text content after removing
all tags inside the element.
<xsl:template match="person">You need separate templates to say how to process name elements. Note that this template for person implicitly says not to process in any way any other child elements.
<xsl:apply-templates select="name"/>
</xsl:template>
<?xml version="1.0" ?>Note that the namespace given, http://www.w3.org/TR/WD-xsl, is for the old version of XSLT implemented by IE 5 and 5.5.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="person/name">
<p>
<xsl:value-of select="name" />
<xsl:apply-templates select="@born" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The XSLT engine automatically removes the XML text declaration when
the root element of the output is <html>. In this case
also, the XSLT engine uses HTML syntax for empty elements like <br>
instead
of XML syntax like <br/>.
<xsl:template match="text()|@*">However, by default attribute nodes are not reached, so by default only the text inside elements is output.
<xsl:value-of select="." />
</xsl:template>
The default top-level template is
<xsl:template match="t*|/">A more specific template always over-rides a more general template. So if you provide a template for certain elements, their children are not necessarily processed.
<xsl:apply-templates/>
</xsl:template>