Sei sulla pagina 1di 137

XSLT In a Nutshell

Paul Prescod, Blast Radius Products Co-Author: XML Handbook paul@prescod.net

What is XSLT
A language for transforming XML:
From a structural vocabulary like DocBook to a presentation vocabulary like HTML Between similarly vocabularies Even within the same vocabulary

Batch Formatting
Transform XML into vocabulary suitable for display Most common targets:
HTML (for legacy display) XSLT Formatting Objects (one day)

Direct Browsing of XML Files


Transform on client side Browser can apply XSLT style sheets that produce HTML Browser directly displays the HTML

Inter-vocabulary Translation
Any input vocabulary is legal Any output vocabulary is legal Even:
Proprietary Non-visual

"Massaging" Data
Querying for particular information Sorting on elements and attributes Filtering elements and attributes Output could be new vocabulary or old one

"Dumbing Down" Data


Formatting-oriented transformations "dumb-down" data Domain-specific, semantic elements become generic, formatting-oriented elements

Reusing Data
For example, in the online rendering of an XML document representing an encyclopedia, the article title might be:
in the page that represents the article itself in the header in the footer in the Table of Contents in a "listing by author" in a "listing by subject" in cross-references

Example: Input
<repairs> <repair> <date>...</date> <location>...</location> <reason>...</reason> </repair> <repair> <date>...</date> <location>...</location> <reason>...<reason> </repair> </repairs>

Example: Output
<table> <headings> <head>Location</head><head>Date</head><head>Reas on</head> </headings> <row><cell>...</cell><cell>...</cell><cell>...</cell></row> <row><cell>...</cell><cell>...</cell><cell>...</cell></row> </table>

10

Transformational Features
Headings row added Location and date switched around Elements renamed
Repairs --> table Date --> cell Location --> cell Reason --> cell

11

Transformation Terminology
XSLT Stylesheet = collection of "template rules" Template Rule = pattern + template Every input element is processed with a single rule The "right rule" is found based on pattern The rule applies the template

12

Formatting Terminology
Templates create result elements Result elements can conform to any vocabulary

13

Result Element Vocabulary


Depending on namespace, could be:
HTML: can be displayed by legacy a browser XSLT Formatting objects: displayed by FO-aware browser or printed other vocabulary: further processing as needed

14

XSLT and HTML


Modern and legacy browsers understand HTML XSLT can generate HTML HTML generation can be done on client or server 6.0 browsers allow generation on client

15

XSLT and XSL FO


Used more often for print than online Future browsers may understand XSL formatting objectsbut probably not "FOP" tool can batch-convert them into PDF Commercial tools also support xsl:fo. For instance Renderx (has SVG support!) and Antenna House

16

XSLT Versions
The current version is 1.0. 2.0 is being designed. It is somewhat more complex and sophisticated. It builds on XPath 2.0, which is strongly type-checked. It supports all XML Schema types and can do appropriate conversions between them.

17

XPath: Node Addressing in XML

What is XPath?
Data must be found before it can be worked with Document components can be located by
name (components with URIs or IDs) position (in document hierarchy or character stream) structural relationship (to some other located component)

XPath is a simple query/addressing language for XML XPath expressions are applied to XML documents to return node sets. Some node sets contain a single element but others contain multiple nodes of arbitrary types (text, attribute, etc.)

19

A Basic XPath
Return the root (document) element if it is of type DOC /DOC It is just like a DOS or Unix path referencing a file in the root directory

20

Path-like XPaths
Return the TITLE child (assuming there is only one) of the DOC document element /DOC/TITLE

21

Query-like XPaths
Return all SECTION children of the DOC document element /DOC/SECTION

22

Multi-level XPaths
Return all TITLE children of all SECTION children of the DOC document element /DOC/SECTION/TITLE

23

Wildcards in XPaths
Return all TITLE children of all children of the DOC document element /DOC/*/TITLE In other words, all TITLE grandchildren The wildcard matches elements of any element type It matches only one level

24

Matching Multiple Levels


Return all TITLE nodes anywhere within all DOC/SECTION elements /DOC/SECTION//TITLE Return all TITLE nodes anywhere within all SECTION elements anywhere within the DOC document element /DOC//SECTION//TITLE Return all TITLE nodes anywhere within the document: //TITLE We call these "descendant queries"

25

Matching Other Node Types


Get all child text nodes from TITLE children of DOC /DOC/TITLE/text() Get all comments //comment() Get processing instructions /DOC/processing-instruction()

26

Matching Parents
.. represents the parent node Return elements directly containing FOOTNOTEs //FOOTNOTE/.. Return footnoes parent elements' TITLE children //FOOTNOTE/../TITLE

27

Matching Attributes
@foo represents an attribute named "foo" Security attributes of SECTION: //SECTION/@security All security attributes in document //*/@security

28

Evaluation Context
Every XPath is evaluated in a context:
For an XPointer used in a link, the context is the root of the document into which it points In XSLT, the context is "the node you are working on" (the current node)

To get the context node itself, use "."

29

Relative XPaths
The XPath ./P (or just P) finds all elements of type P that are children of the context node The XPath ./* (or just *) finds all elements of all types that are children of the context node

30

Understanding Context
<DOC> <SECTION ID="Top-level"> <SECTION ID="Contained.1"/> <SECTION ID="Contained.2"/> </SECTION> </DOC> In the context DOC, XPath: SECTION (or ./SECTION) Returns a single node The other SECTIONs are not children

31

Predicates
Filter result nodesets Predicates are specified with square brackets The most common types of predicates are:
attribute existence subelement existence position

32

Attribute Predicates
Sections with a security value of "TOPSECRET"
//SECTION[@security="TOPSECRET"]

Sections with a security value defined


//SECTION[@security]

All name attributes of elements with security attributes


//SECTION[@security]/@name

33

Subelement Predicates
Sections containing an image
//SECTION[IMG]

Sections containing an image with a caption


//SECTION[IMG/CAPTION]

34

Positional Predicates
A numeric predicate tests that a node corresponds to a position Selects third SECTION
//SECTION[3]

Selects last SECTION


//SECTION[last()]

Selects second last SECTION


//SECTION[last()-1]

Third SUBSECTION of fifth SECTION


/DOC/SECTION[5]/SUBSECTION[3]

35

Predicate Expressions
To refine an address, in a predicate you can use
other location path expressions strings numbers operators, including or and and to express alternates or unions functions (XPath defines a core set)

36

Core Functions
XPath's core function library includes
node set functions, e.g.: id(), last(), position(), count() string functions, e.g: contains(), startswith(), normalize() boolean functions, e.g.: true(), false(), lang() number functions, e.g.: number(), sum(), round()

37

Some Equality Operators


= : equal != : not equal <, > : less/greater than <=, >= : less/greater than or equal to

38

Boolean Operators/Functions
or: e.g.
section[@title or @name] (one or other)

and:
section[@title and @name]
(both)

39

Numeric Operators
+ : add - : subtract div : divide * : multiply mod : modulus

40

Conversion Functions
number() string() boolean()

41

Alternates
We can express a logical union Elements of element type a or b:
a|b

Nodes that are either "a" elements or text nodes


a|text()

42

XPath Unabbreviated Syntax


(quick overview) XPath is a set of steps separated by "/" Each step can have:
"axis" "node test" "predicate" axis::nodetest[predicate]/axis::nodetest[predicat e] ./child::p/attribute::align

43

Extending Functionality
Systems that use XPath can add functions and features to suit their needs Most XSLT implementations add their own features.

44

XSLT Basics: Extracting Data with Templates

In and Out
Input to an XSLT process is
a transformation or template, and a source document

Output is an XML tree or text file In XSLT, the terms "stylesheet" and "transformation" are interchangable

46

XSLT Process
INPUT

OUTPUT
Source Tree

XSLT PROCESS
Output Template: Stylesheet/ Transformation

Result Tree or Text File

47

Transformations and templates


XSLT can be used for "transformations" and for "template documents" XSLT "template document" is a single template transformation Most transformations are made up of many templates Templates pull information out of documents A transformation alternates control between templates and the document

48

An Input Document
In an XSL-implementing browser: <?xml version="1.0"?> <?xml-stylesheet href="stylesheet-name.xsl" type="text/xsl"?> <book><title>Catch-22</title> <logo url="catch22.jpg"/> <description>...</description> </book> Put the stylesheet declaration after the XML declaration in the XML file

49

Pulling information into Output


Template document: <html xsl:version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"> <head><title>A document</title></head> <body> <p>Here is the title of the book: <xsl:value-of select="/book/title"/> <img src="{/book/logo/@url}"/> </p> </body> </html>

50

XSLT Namepace
The real XSLT Namespace is: http://www.w3.org/1999/XSL/Transform Some older stylesheets support an Internet Explorer 5 syntax: "http://www.w3.org/TR/WD-xsl" Run away! These stylesheets depend on behaviors that are slightly different than the standard.

51

Template components
Blindly reproduced to output:
Elements not in the XSLT namespace (literal result elements) Text in the stylesheet (literal text)

Processed to produce output:


XSLT instructions (elements in the XSLT namespace), e.g. xsl:value-of Attribute templates in literal result elements (delimited by curly braces {}

52

xsl:value-of
xsl:value-of outputs a computed value select attribute computes value Usually used to fetch data from input tree
e.g. <xsl:value-of selelct=/book/title/>

53

Value of a Node
The value of a text node is its character data The value of an element is the character data of all of the text nodes directly contained or contained by descendants of the element The value of an attribute is the character data in its literal value

54

Full Transformations

Stylesheet constituents
Instructions at the top level
affect the entire transformation process include template rules (<xsl:template>) and other instructions and declarations

Instructions within templates


direct recursive template application (<xsl:apply-templates>) direct data extraction (xsl:value-of) govern creation of particular output nodes

56

<xsl:template>
<xsl:template> elements contain most of the code for an XSLT transform <xsl:template> elements define template rules A template rule matches input nodes to an output template E.g. "when you see an EXAMPLE element:"
"Make a horizontal line." "Output the text 'Example'." "Output the example number."

57

Template Rule Anatomy


A match attribute on <xsl:template> contains the pattern for choosing input nodes for processing The <xsl:template> element's content is the template to be applied to the matching nodes
literal result elements (e.g. <h1>) literal text (e.g. "Hello") "xsl:" instructions (e.g. xsl:apply-templates)

58

A Template Rule
This example uses HTML result element types: <xsl:template match="EXAMPLE"> <hr/> <!-- horizontal rule --> <p>Example <xsl:number level="any" from="chapter"/></p> <pre> <!-- PRE element --> <xsl:apply-templates/> </pre> </xsl:template>

59

Rule Dependence
A rule for an element may need to process other elements ("nodes") E.g. 1: A rule for processing a chapter is dependent on rules for processing paragraphs E.g. 2: A rule for processing a cross-reference may be dependent on a rule for processing the target element

60

"Recursive" Rule Application


The stylesheet uses the "root rule" (or a default) That rule calls rules for its children (because it is dependent on those rules) ...And so on, and so on, down the tree Each rule calls other rules using the xsl:applytemplates instruction

61

Which rule to apply?


There are many rules Each rule knows how to handle certain elements, but not others Each rule has a pattern that describes what rule applies Pattern syntax is a subset of XPath

62

Example Document
<doc> <section> <title></title> <p></p> </section> <section> <title></title> <p></p> </section> </doc>

63

Example Transformation
<xsl:stylesheet version="1.0" xmlns:xsl="http://"> <xsl:template match="doc"> <html><body> <xsl:apply-templates/> </body> </html> </xsl:template>

64

Example (contd)
<xsl:template match="section"> <div> <xsl:apply-templates/> </div> </xsl:template>

65

Example (contd)
<xsl:template match="section/title"> <h1><xsl:apply-templates/></h1> </xsl:template> <xsl:template match="p"> <p><xsl:apply-templates/></p> </xsl:template>

66

What if no rules match?


There are implicit default rules built into every stylesheet These rules are called automatically if no other rule matches The built-in default rules process sub-elements and output text You could override them with your own default rules, but you would rarely do so

67

<xsl:apply-templates>
The <xsl:apply-templates> instruction goes within <xsl:template> content The processor processes each node with the applicable template By default, apply-templates processes all subelements and text nodes of the current node.

68

The select attribute


The element can have a select attribute that tells the processor which nodes from the input node set to process Otherwise it processes all child nodes.

69

Simple Example
Goal: transform a slideshow in XML into something simpler Target DTD is similar to HTML All element type names are from HTML

70

Input
<slideshow><title>My Title</title> <slides> <slide><title>Slide 1</title> <point>Point 1</point> <point>Point 2</point> </slide> <slide><title>Slide 2</title>... </slide> </slides> </slideshow>

71

Output
<html> <title>My Title</title> <h1>My Title</h1> <hr/> <h2>Slide 1</h2> <ul> <li>Point 1</li> <li>Point 2</li></ul> ... </html>

72

XSLT Design Procedure


Do the work required to make a minimal stylesheet Examine your input document type Start from the top (root, or document element) Handle document element's sub-elements Handle their sub-elements, etc.

73

The Minimal Stylesheet


<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"> <!-- Template rules go here --> </xsl:stylesheet>

74

Starting at the Top


Sketching the slideshow output template <xsl:template match="slideshow"> <html> <title>...</title> <h1>...</h1> ... </html> </xsl:template>

75

slideshow Element Type


<xsl:template match="slideshow"> <html> <title> <xsl:apply-templates select="title"/> </title> <h1> <xsl:apply-templates select="title"/> </h1> <xsl:apply-templates select="slides"/> </html> </xsl:template>

76

title Element Type


We just want the text Our children are all text nodes Text nodes are automatically output <xsl:template match="title"> <xsl:apply-templates/> </xsl:template>

77

slides Element Type


We just want to handle the children <xsl:template match="slides"> <xsl:apply-templates/> </xsl:template> Look familiar? This rule is so common it is built-in So we didnt really have to do these rules at all!

78

slide Element Type


<xsl:template match="slide"> <hr/> <h2> <xsl:apply-templates select="title"/> </h2> <ul> <xsl:apply-templates select="point"/> </ul> </xsl:template>

79

point Element Type


<xsl:template match="point"> <li><xsl:apply-templates/></li> </xsl:template>

80

We're done!
XSLT Stylesheet evaluation will start with the root node The root node represents the whole document Evaluation will proceed to the document element node (slideshow) Then to each of its children ...And so on, and so on

81

Final Stylesheet - 1
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform">

82

Final Stylesheet - 2
<xsl:template match="slideshow"> <html> <title> <xsl:apply-templates select="title"/> </title> <h1> <xsl:apply-templates select="title"/> </h1> <xsl:apply-templates select="slides"/> </html> </xsl:template>

83

Final Stylesheet - 4
<xsl:template match="slide"> <hr/> <h2><xsl:apply-templates select="title"/></h2> <ul><xsl:apply-templates select="point"/></ul> </xsl:template> <xsl:template match="point"> <li><xsl:apply-templates/></li> </xsl:template> </xsl:stylesheet>

84

Executing the XSLT Processor


saxon [xmlfile.xml] [stylesheet.xsl] > [output.xml] saxon simple.xml simple.xsl > simple.htxml Good choices for processors include Xalan, MSXML, Saxon, 4XSLT

85

Exercise: subpoints
How could we implement subpoints? <slide><title>A slide title</title> <point>A point <subpoints> <point>First subpoint</point> <point>Second subpoint</point> <point>Third subpoint</point> </subpoints> </point> </slide>

86

Exercise: subpoints cont'd


<h2>A slide title</h2> <ul> <li>A point <ul> <li>First subpoint</li> <li>Second subpoint</li> <li>Third subpoint</li> </ul> </li> </ul>

87

Implementing subpoints
<xsl:template match="subpoints"> <ul> <xsl:apply-templates/> </ul> </xsl:template>

88

Will this rule ever get called?


Yes: the point rule will call it <xsl:template match="point"> <li><xsl:apply-templates/></li> </xsl:template>

89

Template Recursion

SOURCE slide point <ul>

RESULT <li>...

subpoints
point ... ...

<ul>
<li>...</li> ... </ul> </li>
90

Looping
xsl:for-each lets us do the same thing for many nodes The body of the xsl:for-each is a full template It is instantiated once for each match Each time a different node is the "current" node

91

Example of Looping
<xsl:template match="repairs"> <TABLE> <xsl:for-each select="/repairs/repair"> <ROW> <TD><xsl:value-of select="date"/></TD> <TD><xsl:value-of select="location"/></TD> </ROW> </xsl:for-each> </TABLE> </xsl:template>

92

Current Node
Relative location paths are relative to the current node The current node is also available through a current() function <xsl:for-each select="/class/instructor"> Teacher: <xsl:value-of select="/teachers/teacher [@name=current()/@name]"/> </xsl:for-each>

93

Conditional Processing

Conditionals: xsl:if
E.g.: Only build a Table of Figures if there are figures <xsl:if test=".//figure"> <h1>Table of Figures</h1> <ul> ... </ul> </xsl:if>

95

Conditionals: <xsl:choose>
xml:choose is necessary when you need multiple options xsl:otherwise is like "else" Only one option is chosen, or else xsl:otherwise is used

96

Using <xsl:choose>
<xsl:choose> <xsl:when test="..[@type='chapter']"> Chapter</xsl:when> <xsl:when test="..[@type='appendix']"> Appendix</xsl:when> <xsl:otherwise> Section</xsl:otherwise> </xsl:choose>

97

Advanced Feature Overview

Creating Element Nodes


In addition to literal result elements, xsl:element instructions can be used in templates to create new element nodes <xsl:element name="p" namespace="http://www.w3.org/HTML"> </xsl:element> <xsl:element name={@real_tagname}" namespace="http://www.w3.org/HTML"> </xsl:element>

99

Computing Attribute Values


The xsl:attribute instruction creates a new attribute node, or replaces the value of an existing attribute node, on the containing element: <img> <xsl:attribute name="src"> <xsl:value-of select="/book/logo/@url"/> </xsl:attribute> </img> Equivalent to using an attribute value template: <img src="{/book/logo/@url}">

100

Text Nodes
<xsl:text>This is text</xsl:text> xsl:text is good for inserting whitespace: <xsl:text> </xsl:text>

101

Numbering Nodes in Output


xsl:number creates a formatted number for insertion in output tree (Overview!) <xsl:number level = "single"|"multiple"|"any" count = pattern from = pattern value = number-expression format = {string} lang = {nmtoken} letter-value = {"alphabetic"|"traditional"} grouping-separator = {char} grouping-size = {number}/>

102

Processing Instructions
<xsl:processing-instruction name="xml-stylesheet"> href="book.css" type="text/css" </xsl:processing-instruction> creates the PI: <?xml-stylesheet href="book.css" type="text/css"?>

103

Comments
<xsl:comment>This file is automatically generated. Do not edit!</xsl:comment> creates the comment: <!--This file is automatically generated. Do not edit!-->

104

Copying
xsl:copy-of: copy of a result-tree fragment xsl:copy: easy way of copying the current node

105

xsl:copy-of
<xsl:template ...> <xsl:copy-of select="/foo/bar"/> </xsl:template> Copies selected elements from source to result Children are also copied Can also insert result tree fragments: <xsl:variable name="myvar"> <a><b/></a> </xsl:variable> <xsl:copy-of select="$myvar"/>

106

xsl:copy
<xsl:template match="p"> <xsl:copy/> </xsl:template> Namespace nodes of the current node are automatically copied Attributes and children of the node are not automatically copied

107

xsl:variable
Variable values can be numbers, strings, booleans, node-sets It is also possible to hold "result tree fragments": <xsl:variable name="res-tree"> Hello, my name is: <xsl:value-of select="@name"/> </xsl:variable> name attribute is name of variable Value is specified in select attribute or content Variables cannot be overwritten

108

Using xsl:variable
<xsl:template match="student"> <xsl:variable name="student-name" select="name"/> Congratulations <xsl:value-of select="$name"/>! <xsl:value-of select="$name"/>, you are soon to be the winner of our sweepstakes! Your friends will all say, I wish I were <xsl:value-of select="$name"/>. </xsl:template>

109

Parameters
Parameters are inputs from the "application" Could be specified through:
command line arguments browser GUI environment variables .ini file

If not specified, they "default"

110

xsl:param
<xsl:param name="foo"> Hello, my name is <xsl:value-of select="@name"/>. </xsl:param> <xsl:param name="foo" select="/foo/@default"/> A missing default is equivalent to empty string

111

Template Calling
xsl:apply-templates xsl:call-template <xsl:call-template name="foo"/> xsl:call-template is like apply-templates but:
template is chosen by name mode and select attributes are irrelevant does not change current node

112

Passing parameters
xsl:with-param: <xsl:call-template name="foo"> <xsl:with-param name='myparam1'> value </xsl:with-param> </xsl:call-template> <xsl:apply-templates/> <xsl:with-param name='myparam' select='value'/> </xsl:apply-templates>

113

Modes
What if we need the same element to be processed in many different ways?
As a heading As a TOC entry As an index entry For cross references

We need to write four different rules that apply to the same element Each rule will operate in a different mode

114

Using Modes
A template can declare that it only works in a particular mode <xsl:template match="..." mode="..."> ... </xsl:template> An apply-templates instruction can declare that it needs a template that has a certain mode: <xsl:apply-templates select="..." mode="..."/>

115

Modes Example
<xsl:template match="SECTION"> ... </xsl:template> <xsl:template match="SECTION" mode="TOC"> ...TOC handling... </xsl:template> <xsl:template match="BOOK"> <h1>Table of Contents</h1> <xsl:apply-templates mode="TOC"/> <hr/> <xsl:apply-templates/> </xsl:template>
116

Using Additional Stylesheets

Inclusion Instructions
xsl:include: include another stylesheet xsl:import: include ... with lower precedence

118

xsl:include
Includes another stylesheet Absolute: <xsl:include href="http://.../foo.xsl"/> Relative: <xsl:include href="foo.xsl"/> Stylesheets may not include themselves directly or indirectly

119

Import Instructions
Like inclusion except that definitions in the importing stylesheet take precedence over those in the imported stylesheet Absolute: <xsl:import href="http://.../foo.xsl"/> Relative: <xsl:import href="foo.xsl"/>

120

Input Management

Input Descriptions
xsl:key: define searchable index xsl:namespace-alias: equate two namespaces xsl:strip-space: define space stripping element types xsl:preserve-space: define space preserving element types

122

Keys
Keys allow you to look up elements by name:
Customers by phone number Chapters by a unique identifier

The same element can be have two keys:


Employees by employee ID Employees by social security

123

Key Example: info.xml


<employees> <employee employeeID="e98302"> <social-secur>000-00-0000</social-secur> <name>Anthony Sobers</name></employee> <employee employeeID="e02322"> <social-secur>111-11-1111</social-secur> <name>Mossy Rock</name></employee> </employees> <department> <person empid="e98302"/> <person empid="e02322"/> </department>
124

Declaring Keys: foo.xsl


<xsl:stylesheet ...> ... <xsl:key name="employees" match="employee" use="@employeeID"/> <xsl:key name="soc-sec" match="employee" use="social-secur"/> </xsl:stylesheet>
125

Using Keys: foo.xsl


<xsl:template match="department">

<xsl:value-of select='key("employees","e98302")/name'/>
<xsl:value-of select='key("employees",@empid)/name'/> </xsl:template>

126

Avoiding Name Clashes


What if you want to generate an XSLT stylesheet, or have software that searches for HTML title elements? How do you make an xsl: or html: element without triggering XSLT or HTML processing?

127

xsl:namespace-alias
<xsl:namespace-alias xmlns:axsl="http://something/bogus" stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="/"> <axsl:stylesheet> ... </axsl:stylesheet> </xsl:template>

128

Space Stripping
In machine to machine applications, whitespace between nodes is usually irrelevant xsl:strip-space strips space from specified elements Strip space from address and date elements: <xsl:strip-space elements="address date"/> Strip space from all elements: <xsl:strip-space elements="*"/>

129

Space Preserving
If certain element types need spacing to be preserved: <xsl:preserve-space elements="foo bar"/>

130

Output Management

Output Descriptions
xsl:output: various output options xsl:decimal-format: printing numbers

132

xsl:output
(Quick overview!) <xsl:output method = "xml" | "html" | "text" | other version = nmtoken encoding = string omit-xml-declaration = "yes" | "no" standalone = "yes" | "no" doctype-public = string doctype-system = string cdata-section-elements = qnames indent = "yes" | "no" media-type = string />

133

Error Management

Messages
xsl:message generates messages Presentation depends on application:
GUI dialog box standard error logfile

<xsl:if test="not( /foo/bar )"> <xsl:message> Sorry, you need a /foo/bar </xsl:message> </xsl:if>

135

Fallback
If you see xsl:foo and don't know how to handle it, you should look for an xsl:fallback element <xsl:foo> <xsl:fallback>Sorry, your XSLT processor doesn't have that feature! </xsl:fallback> </xsl:foo>

136

More Information
Specs:
http://www.w3.org/TR/xslt http://www.w3.org/TR/xpath.html http://www.w3.org/TR/xslt20/ http://www.w3.org/TR/xpath20/ XSLT : Programmer's Reference by Michael Kay (Author) Beginning XSLT by Jeni Tennison XSLT and XPath On The Edge by Jeni Tennison Definitive XSLT and XPath by G. Ken Holman

Several good books:

Mailing list:
http://www.biglist.com/lists/xsl-list/

Contact me for slides:


paul@prescod.net pprescod@blastradius.com

137

Potrebbero piacerti anche