<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<head>
<title>Silly Example</title>
</head>
<body>
<h1>Silly Example</h1>
<p>You'd probably use extension elements, or somthing
more interesting in real life: 3+4 is <xsl:value-of select="3+4"/>.
</p>
</body>
</html>
A Complete Example
This is a simple stylesheet that transforms source <para> and <emphasis>
elements into HTML:
The match pattern determines where this
template applies
Literal result element(s) come from non-XSL
namespace(s)
XSLT elements come from the XSL namespace
Match Patterns (Locating Elements)
One critical capability of a stylesheet language is to locate source
elements to be styled. CSS, for example, does this with "selectors."
FOSIs do it with "e-i-c's", elements in context. XSLT does it
with "match patterns" defined by the XML Path Language (XPath) (http://www.w3.org/TR/xpath).
XPath has an extensible string-based syntax
It describes "location paths" between parts of
a document or documents
One inspiration for XPath was the common "path/file"
file system syntax
Two things to remember about XPath expressions:
Pattern matching occurs in a context; XPath expressions and
XSLT elements can change the current context and consequently the nodes which
match
XPath is inclusive or greedy, it addresses all
matching elements. You must use predicates to refine the set of
nodes selected.
Pattern Examples
para
Matches all <para> children in the current context
para/emphasis
Matches all <emphasis> elements that have a parent of <para>
/
Matches the root of the document
para//emphasis
Matches all <emphasis> elements that have an ancestor
of <para>
section/para[1]
Matches the first <para> child of all the <section> children in
the current context
//title
Matches all <title> elements anywhere in the
document
.//title
Matches all <title> elements that are descendants of the current
context
More Complex Patterns
section/*/note
Matches <note> elements that have <section> grandparents.
stockquote[@symbol]
Matches <stockquote> elements that have a "symbol" attribute
stockquote[@symbol="XXXX"]
Matches <stockquote> elements that have a "symbol" attribute
with the value "XXXX"