Slides of the presentation …
(If your
browser has proper implementation of the object
element of XHTML
(e.g., Mozilla’s Firefox) and you have a SVG plugin installed, you might
want to use the same slideset using SVG.
Some of the images may have added interaction and they also rescale
better…)
XSL-FO
describes a “printable” page with text
XSL-FO
XML dialectExtract from a CD collection in XML:
<cd>
<artist>Aatabou, Najat</artist>
<title>The Voice of the Atlas</title>
<catalog>CDORBD 069</catalog>
<time>61.15</time>
<filed>C05 World</filed>
<playlist>
<work>Baghi narajah</work>
<work>Finetriki</work>
<work>Shouffi rhirou</work>
<work>Lila ya s'haba</work>
<work>Ouardatte lajnane</work>
<work>Ditih</work>
</playlist>
</cd>
<xsl:template match="/">
<html>
...
</html>
</xsl:template>
<xsl:template match="/">
<html>
...
<xsl:for-each select="cd/artist">
<h3>Artist</h3>
<p> <xsl:value-of select="." /></p>
</xsl:for-each>
</html>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="cdlist/cd">
<H1><xsl:value-of select="artist"/></H1>
<hr />
<p class="01"><xsl:value-of select="title" /></p>
<p class="02">Label:<xsl:value-of select="label"/>
Number:<xsl:value-of select="catalog"/>
Time:<xsl:value-of select="time"/></p>
<p class="03">Stored at:<xsl:value-of select="filed"/></p>
<p class="04">Playlist:</p>
<ul>
<xsl:for-each select="playlist/work">
<li class="05"><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>
<hr />
</xsl:template>
This is referred to as a “pull” model (all patterns are pulled into the root template)
The Voice of the Atlas
Label: , Number: CDORBD 069 , Time: 61.15
Stored at: C05 World
Playlist:
Template pushes nodes out to be handled by other templates:
<xsl:template match="/">
<xsl:for-each select="cdlist/cd">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
Ie, look for the other templates starting by the current context (already handled)
<xsl:template match="artist">
<H1 class="emph1"> <xsl:value-of select="."/></H1>
</xsl:template>
<xsl:template match="title">
<p class="01"><xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="label">
<p class="02">Label:<xsl:value-of select="."/> </p>
</xsl:template>
...
<xsl:template match="filed">
<p class="05">Stored at:<xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="playlist">
<p class="06">Playlist:</p>
<ul>
<xsl:for-each select="work">
<li style="..."><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>
You can generate many different output styles from the same dataset
For example:
Such technique is of a vital importance in:
Use:
<xsl:output
method="xml" version="1.0" indent="yes"
omit-xml-declaration="no" encoding="utf8"
doctype-public="-//W3C//DTD SVG 20010904//EN"
doctype-system="...DTD/svg10.dtd"
media-type="image/svg+xml"/>
to get:
<?xml version="1.0" encoding="utf8"?>
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 20010904//EN"
SYSTEM "...DTD/svg10.dtd">
XSLT Element | Description |
---|---|
xsl:apply-templates
|
Finds correct template to apply |
xsl:template
|
Defines a template |
xsl:element
|
Generates an element |
xsl:attribute
|
Generates attribute node |
xsl:value-of
|
Evaluates select and outputs value |
xsl:text
|
Generates text literaly |
xsl:copy and xsl:copy-of
|
Shallow/deep copy of a node |
xsl:choose
|
Conditional testing |
xsl:for-each
|
Cycle based on test |
xsl:if
|
Conditional test |
xsl:sort
|
Sort the elements |
<xsl:for-each select="cdlist/cd" >
<xsl:sort select="title" />
...
</xsl:for-each >
CDs ordered by title
Goal: colour code the different types of CD
xsl:choose
provides an "either or" processing<tbody>
<xsl:for-each select="cdlist/cd">
<tr>
<xsl:attribute name="style">color:
<xsl:choose>
<xsl:when test="filed[. = 'C05 World']">lime</xsl:when>
<xsl:when test="filed[. = 'C06 Country']">yellow</xsl:when>
<xsl:when test="filed[. = 'C11 Jazz Trad']">orange</xsl:when>
<xsl:when test="filed[. = 'C01 Pop']">red</xsl:when>
<xsl:otherwise>white</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="filed"/></td>
</tr>
</xsl:for-each>
</tbody>
It tests the content of the element "filed" to set the style
<xsl:for-each select="cdlist/cd[filed = 'C06 Country']" >
parent
child
following-sibling
preceding-sibling
ancestor-or-self
and
descendant-or-self
para
elements, and first in the
list:child::para[position()=1]
para[position()=1]
*
: selects all@name
: selects the name atribute of the context nodelast()
: selects last.
: selects the context nodefor-each
, etc./
/
for root, followed
by relative path/doc/chapter[3]/section
*/para
style
which has svg
as an ancestor://svg//style
para
nodes, that are children of the context
node, with attribute type
set to main
, select
the third one:para[@type="main"][3]
employee
children of the context node that
have both secretary
and assistant
attributes
set:employee[@secretary and @assistant]
<xsl:if test="number(substring(.,5,2))=25">
Example for the usage of axes in XSLT:
<xsl:for-each select="cdlist/cd/work">
<xsl:choose>
<xsl:when test=". = 'Sweet Lorraine'" >
<td>
<xsl:value-of select="ancestor::cd/artist"/>
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
element(*,datatype)
for $a in fn:somefilter(/bib/book/author) return ($a/title)
XSLT+XPath
It is around, use it!