Extensible Stylesheet Language (XSL)

Extensible Stylesheet Language
(XSL)
Brian Temple
about:XSL
• XSL is a language for expressing
stylesheets
– a language for transforming XML documents
– an XML vocabulary for specifying formatting
semantics
But, why XSL?
• Unlike HTML, XML element names have
no intrinsic presentation semantics
• Builds on prior work of CSS2, DSSSL
• Can be extended
An Example XML Document
<?xml version=“1.0”?>
<purchaseOrder orderDate=“1999-10-20”>
<shipTo country=“US”>
<name>Matthias Hauswirth</name>
<street>4500 Brookfield Dr.</street>
<city>Boulder</city>
<state>CO</state>
<zip>80303</zip>
</shipTo>
<billTo country=“US”>
<name>Brian Temple</name>
<street>1234 Strasse</street>
<city>Boulder</city>
<state>CO</state>
<zip>80302</zip>
</billTo>
<comment>Brian pays</comment>
<items>
<item partNum=“123-AB”>
<productName>Porsche</productName>
<quantity>1</quantity>
<price>129400.00</price>
<comment>Need a new one</comment>
</item>
<item>
<productName>Ferrari</productName>
<quantity>2</quantity>
<price>189000.25</price>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
Simple XSL Document
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<table border="2" bgcolor="yellow">
<xsl:for-each select="records/purchaseOrder">
<tr>
<td><xsl:value-of select="shipTo/name"/></td>
<td><xsl:value-of select="comment"/></td>
<xsl:for-each select="items/item">
<td><xsl:value-of select="price"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Simple XSL Results
XSL:CHOOSE
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<table border="2" bgcolor="yellow">
<xsl:for-each select="records/purchaseOrder">
<tr>
<td><xsl:value-of select="shipTo/name"/></td>
<td><xsl:value-of select="comment"/></td>
<xsl:for-each select="items/item">
<xsl:choose>
<xsl:when match=".[price>100]">
<td bgcolor="red"><xsl:value-of select="price"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="price"/></td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
XSL:CHOOSE Results
Processing a stylesheet
Formatting process
• Build formatting object tree
• Produce refined formatting object tree
– mapping from properties to traits
•
•
•
•
shorthand expansion into individual properties
mapping of corresponding properties
determining computed values
inheritance
• Construct area tree
The Area Model
A Typical Area Tree
Fe Fi
FO Fum
• <doc> <p>This is an
<emph>important
word</emph> in this
sentence that also
refers to a
<code>variable</code
>.</p> </doc>
<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version='1.0'>
...
<xsl:template match="code">
<fo:wrapper font-family="Courier">
<xsl:apply-templates/>
</fo:wrapper>
</xsl:template>
Examples of Formatting Objects
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
bidi-override
block
block-container
character
color-profile
conditional-page-master-reference
declarations
external-graphic
float
flow
footnote
footnote-body
initial-property-set
inline
inline-container
instream-foreign-object
layout-master-set
leader
list-block
list-item
list-item-body
list-item-label
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
marker
multi-case
multi-properties
multi-property-set
multi-switch
multi-toggle
page-number
page-number-citation
page-sequence
page-sequence-master
region-after
region-before
region-body
region-end
region-start
repeatable-page-master-alternatives
repeatable-page-master-reference
retrieve-marker
root
simple-link
simple-page-master
single-page-master-reference
•
•
•
•
•
•
•
•
•
•
•
•
static-content
table
table-and-caption
table-body
table-caption
table-cell
table-column
table-footer
table-header
table-row
title
wrapper