Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
arithmetical operations
processing ID/IDREF cross-references
manipulation of strings
n
Generating text
for content
for attribute values
n
n
n
SDPL 2001
Cross-referencing
n
SDPL 2001
id('sect:intro')
selects the element with unique ID "sect:intro"
id('sect:intro')/para[5]
selects the fifth para child of the above element
Examples
SDPL 2001
String manipulation
SDPL 2001
substring-before("dogbert", "bert") =
substring-before("dogbert", "b") = "dog"
substring-after("dogbert", "g")= "bert"
substring(string, startpos, length?):
substring("dogbert", 1, 3) = "dog"
substring("dogbert", 3) = "gbert"
string-length("dogbert")=7
translate(Str, ReplacedChars, ReplacingChars):
<name alias="Bird">
<first>Charlie</first><last>Parker</last>
</name>
to the form
Charlie ("Bird") Parker
SDPL 2001
SDPL 2001
<xsl:template match="name">
<xls:value-of select="first" />
("<xsl:value-of select="@alias" />")
<xls:value-of select="last" />
<xsl:text>
</xsl:text>
</xsl:template>
n
into form
<img src="/images/Mary.jpg"
width="300" />
7
SDPL 2001
XSLT: Repetition
<xsl:template match="photo">
<img src="/images/{file}"
width="{size/@width}" />
</xsl:template>
n
SDPL 2001
<xsl:for-each select="Expr">
Template
</xsl:for-each>
SDPL 2001
Example (xsl:for-each)
n
10
SDPL 2001
SDPL 2001
11
SDPL 2001
12
XSLT Sorting
becomes
n
13
SDPL 2001
14
n
n
SDPL 2001
15
Conditional processing
n
16
<xsl:choose>
<!-- The first 'when' whose test=true() is
instantiated: -->
<xsl:when test="Expr1"> </xsl:when>
<xsl:when test="Expr2"> </xsl:when>
SDPL 2001
<xsl:if test="Expression">
Template
</xsl:if>
n
SDPL 2001
</xsl:choose>
17
SDPL 2001
18
Generating numbers
19
SDPL 2001
21
SDPL 2001
<xsl:for-each select="//name">
<xsl:variable name="LandF"
select="concat(last, ', ', first)" />
22
</xsl:for-each>
Notes 5.1: Additional XPath & XSLT
Example 3.
Sequential numbering of notes within chapters:
SDPL 2001
20
<xsl:template match="note">
<xsl:number level="any"
from="chapter"
format="(1) "/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title">
<xsl:number level="multiple"
count="chapter|section|subsection"
format="1.1 "/>
<xsl:apply-templates/>
</xsl:template>
SDPL 2001
<xsl:for-each select="//name">
<xsl:sort select="last"/>
<xsl:sort select="first" />
<xsl:if test="not(
preceding::name[first=current()/first
and last=current()/last])">
<LI><xsl:value-of select="last"
/>, <xsl:value-of select="first"/></LI>
</xsl:if>
</xsl:for-each>
SDPL 2001
23
24