Download presentation
Presentation is loading. Please wait.
Published byCuthbert Webster Modified over 9 years ago
1
XSLT I Robin Burke ECT 360
2
Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab
3
History SGML stylesheet language DSSSL document style semantics and specification language very complex based on Scheme for typesetting
4
XML XSL "family" of standards XSL-FO formatting objects typesetting document = a set of geometric areas organized on pages XSLT transformations XPath supports both a language for addressing individual XML nodes
5
XSL-FO Example
6
XSLT HTML example
7
XSLT syntax XML document stylesheet root element templates "rule-based" processing
8
XSLT Processing Let L be a list of nodes Let T be a list of templates style (L, T) = Find a template t matching L Instantiate t using L May call style (L', T) Return instantiated template To process a document style ( { root }, T )
9
Special purpose XSLT is not a general-purpose programming language lacks many conventional facilities technically a "tree-rewriting" language
10
Example Jeep suppliers The first one is <xsl:value-of select="/child::entries/child::entry[position() = 1]/child::address/child::name/child::text()" />
11
Note stylesheet element output type element
12
Running example value-of1
13
XPath XPath expression "/child::entries/child::entry[position() = 1]/child::address/child::name/child::text()" How to read "/" = root and delimiter for steps axis::step = a move in the XML document :: = "that is" or "that are" [] = apply some predicate position () = compute the position of this element in its list of siblings text() = the element content Result is a set of nodes
14
Axes self this node child immediate descendant descendant any descendant attribute attribute list following siblings to the right preceding siblings to the left
15
Steps Depends on axis element name attribute name can be associated with a predicate foo[attribute::bar='5'] entry[position() = 2]
16
XPath shortcuts Axes can be abbreviated default = child @ = attribute // = descendant. = self.. = parent Steps text() can be omitted [position() = n] can be [n] Abbreviated version "/child::entries/child::entry[1]/child::address/child::name/child::text()" "/entries/entry[1]/address/name"
17
Example with simplified syntax
18
XML Document
19
Paths All "name" elements? All advertisers? All non-advertisers? The rating of the second entry? All advertisers with a rating above 3? The second line of every address?
20
For-each May want to operate on all nodes in a set for-each element instantiates contents once for every node in set
21
Example listing just names
22
Multiple templates Typically a stylesheet will have multiple templates Easier to read / debug Templates often correspond to elements More modular
23
Templates template element match attribute describes nodes that use the template content template to instantiate apply-templates element select attribute what nodes to use position shows where in the parent element the result is inserted
24
Example
25
Whitespace XSLT automatically removes whitespace this is often correct when it isn't use text element
26
Path mismatch Biggest source of errors end path has no content Check path local path template match apply-template select Match/select should overlap by one step
27
Example template choice
28
Building an element http:// Becomes foo.org
29
Alternate syntax Becomes foo.org
30
Sorting We can sort node lists after they are selected before they are operated on for-each apply-templates Embed sort element
31
Sorting, cont'd What does this do?
32
Example complex selection and sorting
33
Break / Lab
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.