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

2

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

3

Direct Browsing of XML Files  Transform on client side  Browser can apply XSLT style sheets that produce HTML  Browser directly displays the HTML 4 .

Inter-vocabulary Translation  Any input vocabulary is legal  Any output vocabulary is legal  Even: – Proprietary – Non-visual 5 .

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

formatting-oriented elements 7 ."Dumbing Down" Data  Formatting-oriented transformations "dumb-down" data  Domain-specific. semantic elements become generic.

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 8 . in the online rendering of an XML document representing an encyclopedia.Reusing Data  For example.

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

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

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 .

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 .Result Element Vocabulary  Depending on namespace.

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 objects…but 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 .

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

XPath: Node Addressing in XML .

attribute.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. etc.  Some node sets contain a single element but others contain multiple nodes of arbitrary types (text.) 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  ../TITLE 27 .  Return footnoes’ parent elements' TITLE children //FOOTNOTE/... represents the parent node  Return elements directly containing FOOTNOTEs //FOOTNOTE/.

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

use ". the context is "the node you are working on" (the current node)  To get the context node itself. the context is the root of the document into which it points – In XSLT." 29 .Evaluation Context  Every XPath is evaluated in a context: – For an XPointer used in a link.

/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 .Relative XPaths  The XPath .

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

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. including or and and to express alternates or unions – functions (XPath defines a core set) 36 . in a predicate you can use – – – – other location path expressions strings numbers operators.

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

>= : less/greater than or equal to 38 .Some Equality Operators     = : equal != : not equal <. > : less/greater than <=.

g. section[@title or @name] – (one or other)  and: – section[@title and @name]  (both) 39 .Boolean Operators/Functions  or: e.

: subtract div : divide * : multiply mod : modulus 40 .Numeric Operators      + : add .

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 .

and – a source document  Output is an XML tree or text file  In XSLT.In and Out  Input to an XSLT process is – a transformation or template. 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..</description> </book>  Put the stylesheet declaration after the XML declaration in the XML file 49 .jpg"/> <description>.xsl" type="text/xsl"?> <book><title>Catch-22</title> <logo url="catch22.0"?> <?xml-stylesheet href="stylesheet-name.

w3.Pulling information into Output  Template document: <html xsl:version="1.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 .0" xmlns:xsl=" http://www.

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

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. xsl:value-of – Attribute templates in literal result elements (delimited by curly braces {} 52 .g.

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

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 .

" 57 ." – "Output the text 'Example'. "when you see an EXAMPLE element:" – "Make a horizontal line." – "Output the example number.g.<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. "Hello") – "xsl:" instructions (e.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. <h1>) – literal text (e. xsl:apply-templates) 58 .g.g.

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

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

and so on."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. down the tree  Each rule calls other rules using the “xsl:applytemplates” instruction 61 ...

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

Example Document <doc> <section> <title>…</title> <p>…</p> </section> <section> <title>…</title> <p>…</p> </section> </doc> 63 .

0" xmlns:xsl="http://…"> <xsl:template match="doc"> <html>…<body> <xsl:apply-templates/> </body> </html> </xsl:template> 64 .Example Transformation <xsl:stylesheet version="1.

Example (cont’d) <xsl:template match="section"> <div> <xsl:apply-templates/> </div> </xsl:template> 65 .

Example (cont’d) <xsl:template match="section/title"> <h1><xsl:apply-templates/></h1> </xsl:template> <xsl:template match="p"> <p><xsl:apply-templates/></p> </xsl:template> 66 .

but you would rarely do so 67 .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.

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

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 .

. </html> 72 .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> ..

73 .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.

w3.0" xmlns:xsl= "http://www.Template rules go here --> </xsl:stylesheet> 74 .org/1999/XSL/Transform"> <!-.0"?> <xsl:stylesheet version="1.The Minimal Stylesheet <?xml version="1.

</h1> ..... </html> </xsl:template> 75 .</title> <h1>..Starting at the Top  Sketching the slideshow output template <xsl:template match="slideshow"> <html> <title>..

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 didn’t 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 .

xsl] > [output. MSXML. Saxon.xml simple. 4XSLT 85 .xsl > simple.xml] [stylesheet.htxml  Good choices for processors include Xalan.Executing the XSLT Processor  saxon [xmlfile.xml]  saxon simple.

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 .

. <ul> <li>.Template Recursion SOURCE slide point <ul> RESULT <li>..... </ul> </li> 90 ....</li> .. . subpoints point ..

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 .

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

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 .

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

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 .

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

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 .

strings. 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 . booleans. node-sets  It is also possible to hold "result tree fragments": <xsl:variable name="res-tree"> Hello.xsl:variable  Variable values can be numbers.

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 .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"/>.

they "default" 110 .ini file  If not specified.Parameters  Parameters are inputs from the "application"  Could be specified through: – – – – command line arguments browser GUI environment variables .

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 .

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

.TOC handling.. </xsl:template> <xsl:template match="SECTION" mode="TOC"> ..Modes Example <xsl:template match="SECTION"> . </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 .

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

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

/foo..Import Instructions  Like inclusion except that definitions in the importing stylesheet take precedence over those in the imported stylesheet  Absolute: <xsl:import href="http://.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 .

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

"e98302")/name'/> <xsl:value-of select='key("employees".Using Keys: foo.xsl <xsl:template match="department"> <xsl:value-of select='key("employees".@empid)/name'/> </xsl:template> 126 .

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 .Avoiding Name Clashes  What if you want to generate an XSLT stylesheet.

..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. your XSLT processor doesn't have that feature! </xsl:fallback> </xsl:foo> 136 . you should look for an xsl:fallback element <xsl:foo> <xsl:fallback>Sorry.

w3.org/TR/xslt http://www.w3.com 137 .org/TR/xpath.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.html http://www.w3.com/lists/xsl-list/  Contact me for slides: – paul@prescod.More Information  Specs: – – – – – – – – http://www. Ken Holman  Several good books:  Mailing list: – http://www.net – pprescod@blastradius.w3.biglist.org/TR/xslt20/ http://www.

00203984790934/08 .9.:343 02039841002039950. 47- .4.908  0.- 4/089...700907.3057088.909    .9073.

8094189058805.9&3.0  !.--70. 6:..98.90/-.4.7.07.!.90/$39.

...0 ..834/09089570/.8 34/09089 570/.90(.8905..3.90 . .

9 0( ...834/09089570/.

./5.

997-:90.3    ..

//9074310..9:708948:9907300/8 489$%2502039.903/3:3.9:80!.3/  10.9.//1:3.9438.9:708    .943.9438.9 $890289.3.

$%.93.9.8 97.9 %025.908 .8..

3/ :9 35:994.90 .0888  .381472.-0    .3/97.0/4.943479025.:2039 :95:98.3..381472.703907.397004790910 3$% 90907288908009.943 .3$%574.84:7.3.97.3/ .

088 !&%  &%!&% $4:7.0 %700 $% !# $$ :95:9 %025.90 $908009.$%!74.

381472.943  #08:9%700 47 %090   . %7.

3/90/4.9438.9434:941/4.:20398.9085:31472.8309025.908 %025.90/4.908 $%.908 .3/147  9025.381472.381472.:20398 $%9025.39025.943 48997.702.90 97.3/9025.9073.%7.:2039    .:20398 97.43974-090039025.90/4.381472.9438.908.3-0:80/14797./0:5412.943.381472.381472.9438..

07843  2 89080097018908009 3.3$ 25020393-74807  2.20 8 950909.:2039 3.335:94.

8 -44990. .9.

990 44:7. 5..9.

 /08.75943 .

75943 ./08.

94339010    .7...-44 !:9908908009/0.190790 /0.7.943.

07843  2388995.:2039 928.90/4.!:331472.943394 :95:9 %025.

.

  47.

.

$.

%7./990/4.:2039.381472 0.

990.

0.9../ -4/ 50708909904190-44 8.:0 41800.

-44.

990.

 287..

-44.

44.

:7<.

 .

5 .

-4/ .

92    .

0 %070.205..$%.08  995..2085.$%.

.

  47.

.

$.

381472 $4204/07890800988:55479.%7.3390730954707 839.995.

.

  47.

%#.

3/.7089/11070399..%08089080098/0503/43-0.9. 8 #:3.39089.7/    ..478 9.

:0 41 997-:909025.708:90020398  %093908908009 907..08<    .909 !74.0880/94574/:..9083907.0/944:95:9  020398349390$%3..%025.0 0   8.0 907.90.04:95:9 $%3897:.708:90020398 /0290/-.2085.9438 0020398390$%3..:7 -7.2085.425430398 3/70574/:.

:0 41800.997-:90..:0 414:95:98.8..425:90/..9.:0  800.9 .:80/94109./.:0 &8:.425:908.174235:99700 0  8.9...:0 41 8..

-44.

990 .

    .

907/..'.9.7..7..9....9.907/.439.41 9090934/08/70.907/.  %0..7.4/0 %0..997-:90890.439.:041.398 907.:0    .03/.90934/0898.3.:041.:041.3984190002039 %0.41...3002039890..:041.9.30/47.30/- /08.

: %7.9438 .381472.

:/09025.3/49073897:.943574.:0 41  4.073.90...55.9438 3897:.9/.943 8.097.:.3/ /0.90 .110.9438.9.9909450.381472.9438.943 8.943415.908  /70.43899:0398 3897:...70.970.7.79.74:95:934/08    .09025.:78.0  .9438939025.$908009.908 /70.088 3.55 9025.907:08 89025.9900397097.

4/0147  .439.47439.907:08 9025.89025.30   :95:990909 .3!002039 .250   :95:9900.90   034:800.0835:934/0894.9.90 89025.907:02.324894190.34:95:9 9025.3$%97.381472 89025.0.2503:2-07     .900020398/01309025.900020398.

997-:904389025.%025.90#:03.55 9025.99073147.942 2.4390398909025..909 0  04  83897:.908     .3890  5.90002039 8.90.9438 0  8.90 94-0.0883 %089025.9.550/94902.334/08 907.439.9.708:90020398 0    907.448335:934/08147574.

! 7.250:808%708:90020399508  89025.9.%025.90#:0 %80.902.

3 1742.0.. 47439.5907.7:0  5.250 83:2-070.

.

908.55 9025.5 570 !#002039  8.

 .

570 .

90    .89025.

7:0147574.0883.300/94574..7.30020392.0883..0884907  0020398 34/08   7:0147574.58   7:0147574.709002039    .#:00503/03..02.0883909.0 7:0147.08835.7.-0 /0503/03943.59078/0503/03943 7:08147574.7488 7010703.

:78.:9  %.7:0.#0./01.3/8443 /43909700 .97:0./703 -0.:8098 /0503/0394394807:08 3/8443 ..0#:055..849077:08:8390 8.55 9025.943 %08908009:8089074497:0 47...908 3897:..87:0814798.943    .

3/0.5.5508 !.079...8.7-08.99073839.702..7:0348494.30020398 -:9 34949078 .990739.9    .9/08.7:094.97:0 .7:0.8:-80941!.37:08  .55 %070.8.

.2504.943 990 .:2039 /4. 80.

990 5 .

5 .

943 80.943 990 .80.

990 5 .

5 .

943 .80.

     ./4.

381472..07843 2388995.250%7.943 88908009.

.

908.   89025.55 9025.902.9. 92 -4/ 8./4.

 .

-4/ .

92 .

90    .89025.

80..439 / 89025.943  /.9.250 .902. 8.55 9025.908.

 .

 ./.

90    .89025.

943.902..80.9.250 .439 / 89025.

990  8.55 9025.908.

.

 .

55 9025.902.5 58.908.90 89025.89025.9.

.

5 .

90    .89025.

07  8908009 %0807:08.9.9/01.077/090294:743/01.08 %0-:9 3/01.70/484    .13449077:0 2..9.0/.91347:082.70.3/ 4:95:9909 4:. %070.:97:08  -:94:4:/7.4:/4.:942.7025.:97:08-:93940..:97:08574.0888:- 0020398..9.

:7703934/0    .8:- 0020398.439039 %0574.08808.08847574.3/90934/084190.55 9025..55 9025.90.9083897:.90 /01.-09025.94340893  89025.34/0990 .55 9025.908574.8..088080.:9 .908 %08.55.

08847.088 907809574.34/0817429035:934/080994 574.990890  574.9.0.%0800.997-:909.08808..997-:90 %0002039.9.3./34/08    ...800.

8/0843394842093  82507 %.$250.701742%    .709%882.97.794% 0020399503.208.381472.250 4.

35:9 8/084990%90.

990  8/08 8/0990$/0.

990 5439!439.

5439 5439!439.

5439 .

8/0 8/0990$/0.

990 .

8/0 .

8/08 .

8/084    .

:95:9 92 990%90.

990 %90.

 7.

 $/0.

 : !439.

 !439.

.

: .

92     .

$%083!74.0/:70 49047706:70/942.3/09078:- 0020398 09.2304:735:9/4.232.:2039950 $9.79174290945 7449 47/4.:2039002039 88:- 0020398 .3/0/4.     .0.:2039002039 .8908009  .

07843  2388 995.%032.07843   88908009 .$908009 2.

.

  47.

.

$.

907:084070  .%7.381472  %025.

88908009    .

90  89025.902.9.793.3908/0844:95:99025.990%45 $09.8/084 92 990 .$9.

990  .

 .

92 .

89025.90    .

8/084  92 990 8.55 9025.902.908800.9.9990.8/08402039%50 89025.

 .

990  8.9990.908800.55 9025.

 .

98/08. 8.908800.55 9025.

 .

92 .

89025.90    .

70.99002039%50 0:89.90934/08 %0934/08.4:95:9 89025..908.70.902.990 8.9.9.3990909  :7.55 9025./703.:942.

 .

89025.90    .

8/0802039%50 0:89.902.55 9025./703  89025.8/08 8.9.3994.3/090.908.

 .

    .90 441.7 %87:0884...4224398-:9 3 $40//3 970.89025.9.094/490807:08.2.

8/002039%50 89025.8/0  7.9.902.

9990.  8.55 9025.908800.

 .

908800.95439.55 9025. : 8.

 .

: .

90    .89025.

9.55 9025.908.543902039%50 89025.902.5439  8.

.

 .

89025.90    .

.:2039 .799907449  34/0 %0744934/070570803989040/4.00/9490/4.:.943574.0 70/430 $%$9080090.:.4198..94389../703 3/8443 .:203900203934/0 8/084 %03940.3/8443    .

07843   889080092388 995.3.$908009  2.

.

  47.

.

$.

%7.381472    .

9990.55 9025.908800.902.9.$908009  89025.3.8/084  92 990 8.

 .

990  8.55 9025.9990.908800.

 .

 8.98/08.55 9025.908800.

 .

92 .

90    .89025.

902.9.$908009  89025.8/0  7.3.

 8.55 9025.908800.9990.

.

 :8.95439.55 9025.908800.

.

: .

9.908.90 89025.89025.55 9025.902.5439 8.

.

 .

89025.90 .

88908009    .

0884783.43 $%    .:9390$%!74.43210 2(8908009 8(4:95:9 2(  8.08147574.0.08847 8.4.3 $  $.:/0.438250 28250 88250 92 44/..

07.4:/025020398:-54398  8/09908/0990.808:-54398 4.

990 54395439 8:-54398 54397898:-5439.

43/8:-5439.5439 5439$0.

5439 5439%7/8:-5439.

5439 .

8:-54398 .

5439 .

8/0    .

07.808:-54398.439 / 8/0990.

  : 5439 : 7898:-5439.

 $0.43/8:-5439.

 %7/8:-5439.

 .

: .

 .

:    .

8:-54398  : 8.55 9025.902.908.250203938:-54398 89025.9.

 .

: .

89025.90    .

908.5439 8.987:00.55 9025.0/ 089054397:0..9  89025..0709.902.9.

.

 .

89025.90    .

90#0.:7843  $ &# 8/0 5439 8:-54398 5439  #$&% :  :  .%025.

  .

: .

  .

 ..20931472..90/43.334/08  %0-4/41908147 0..4453 8147 0.1:9025.920.:7703934/0    .9.098:8/4908.90 98389.39.01470.2./110703934/0890.8..

902.250414453 89025.9.78  % 8147 0.800.705...9.

78.705.

7 #  %8.:0 41800.90.705.9/..

.

.94.% %8.:0 41800.943..

.

% .

#  .

8147 0. ..

% .

89025.90    .

:77039  1:3.9435.800....-0974:.04.84.943 8147 0.09490.:7703934/0  %0..9..9.7070.98.9.:7703934/08..:770394/0 #0.

88...

07 8.:0 41 800..3897:.947 %0..9.

.90.078.

07 3.20.:77039 ..90.

3.20(.

 .

.    .8147 0.

43/943.0883 . !74.

-041:70819070.881    3-:/.701:708  819089 .43/943.%.

.

-041:708.1:70 %.

 : .

: .

81    .

4480830.7034:300/2:950  459438 849078080080 3430459438.088.4480 2.4803 4708084907808 :80/    .88.43/943.

.5907 ( .4480 8.4480  8039089 950 .&838.5907.

5503/ ( 5503/.803 8039089 950 .

943.803 8490780 $0.

8490780 .

4480    .8.

9:70 ./.3..0 .07.0/ 0.

.9438.3-0:80/39025..708:90020398 8002039  3897:.2085.//94394907.70.93020394/08 3.70.9030 00203934/08 8002039 3.90894.205 3.0995.

.

  47.

% .

20< 3..8002039 8002039 3.3.2085.20 70.0995.*9.

.

  47.

% .

8002039    .

.:041.9.:0 41800.997-:90  34/0 47705.908.:08 %08.425:93997-:90'.33002039 2 8.997-:903..943.70.0890.997-:903897:.2087..30.997-:90 34/0 4390.439. 8.30893.

-44.

44.

:7.

 .

8.997-:90 .

90 287....03994:83.2 6:.3.:09025.997-:90.

-44.

44.

:7<    .

%094/08 8909%88909.

0 8909.8909  8909844/1473807939085..

8909     .

98973< .97..:03:2-07 05708843 1472.-09.4:395.08302:950.:0.0 83:2-07 0.:2-0734/083 :95:9 83:2-07.99073 .7.3329403< 09907 .99073 17425./943.1472.990/3:2-071473807943  34:95:99700 .< 74:53 805.7< 74:53 803:2-07<.70.07.5.3 ...947.908.

     .

9438 8574.943  3.88 950909.!74.08833897:.202 8908009 701-44 .0883 3897:.

88 ..

943 .88950909.70.90890! 2 8908009701-44 .8574.0883 3897:.

88     ..

9.422039%8108.:942.90/ 4  3490/9.0307.4220398 8..

.9.0307.90/ 43490/9      .422039 .70.422039  %8108.:942.90890.8.

453 8.8.41.2039  8.45 41.708:9 970017.45390.:7703934/0     .4541.450.

9.8.45 41 89025.45 41800.90   8.

144.

7.-.

 .

90 4508800.89025.70.84.094708:9 /703.90/0020398174284:7.7.-..7 ..450/ .202.8438079708:9970017.20398 8.3.-03.

.

. .

.92.-0 8.45 41800.8.7.7..

     .

902.9.8.45.5  8.45 89025.

 .

90 ./703419034/0.9..450/     ..70349 ..9.:942.2085.034/084190.:7703934/0.:942.3/..70 .450/ 997-:908.89025..

.208 8.-0 '.20708 9700 04 23.7.20.3-03:2-078 89738 -440.8.:08.7.:0 41800...20398 8..-0.38   34/0 8098 98.845488-0944/708:9970017.93..-03.7.

 .

997-:9047..20..-0 '.7.7.7..997-:9083.2041.0779903     .8.:08850.3349-04.439039 '.-08.10/3800.-0 3.9.

9.20 800.89:/039  8.902.2089:/039 3.-0 89025.7.20.7..93.&838.-03..

9438 8.20.:0 41800. 437..93.9:.

20..:0 41800. 8.93.

20.8. 4:.93.:0 41800. 8070 8..084:71703/8 .70 844394-0903307414:7 800589.

 .

89025.90     .

7.7.-08 310 1349850.55.7:20398 -74807& 03.209078.422..3/30.7432039.10/974: .:9    .!.10/ 90/01.7035:98174290.209078 !..7.943  4:/-0850.

2 85.20.7.7.85.93.20144  04 23.23.:0 41800.208 8..

 .

9.7.2 85.85.23.20144800.7.

144.

/01.:9.

0399402598973    .:9806:.. 2883/01.

 9025.903.3 8.90.55 9025.908  8. 9025..%025.20144.90 8..

..55 9025.707700. 9025.997-:908.908.30.4803-3.3/800.9080.:7703934/0    .9. 8.39 /408349.20 24/0..908-:9 9025.

20 25.!.2  8.20144 89 5.903.8835.7.7. 9025..209078 89 5.:0 .7..23.7.2  .

89 5.7.2 .

.55 9025.90 8.908. 9025.8.

9 .2  800.7.2 3. 89 5.7.20 25.:0 ..

 .

908    .8.55 9025.

/3 8.4/08 .7:04507.3/1107039.559490 8.9..910300/908.08 0300/9479014:7/11070397:089.0.0880/3  2.903.33/00397 47.8 8.74887010703./110703924/0    .% 0397 8.20002039 .2000203994-0574.

  5..79.99434783.9.3/0. 24/0  .709.:..90.902.&834/08 9025.724/0 89025.

89025.9 24/0 .324/0 8.8.55 9025.90 3.9083897:..943.909..908800.55 9025.3/0..9025.9.709.99 300/8.079.

    .

4/08.9.250 89025.902.$%   .

902.90 89025.89025.9.3/3 .$% 24/0%  % .

-0414390398.902.90 89025.89025.  %.9.

90824/0% .55 9025. 8.

 7.

 8.55 9025.908.

 .

90    .89025.

 $9080098 .&83//943.

:/03.349078908009  8254793.:/0.:/0 9407570.0    .9438 83.:8433897:.3.0/03.

349078908009  -84:90 83.83.:/08.:/0 3.:/0701995.

.

.

144 8.

9.0 83.:/0701144 8. #0.

947 3/70. $90800982.3493.08/70.:/090280.9    .

0599.079480390254790/ 8908009 -84:90 825479701995.9438 03.254793897:.0/03.0570.04.:8430.9/0139438390254793  89080099.

.

.

144 8.

 #0.0 825479701144 8.9.

    .

3.35:9 .02039 .

08 88975 85.0 85.7...2085.3002039 9508    .806:..2085..08975530020399508 8570807.0570807..0 .0/013085.0/013085....35:908.759438 80/013080.-03/0  83.90943.

20002039.09408 254008-025400 254008-84..80.20  :8942078-54303:2-07 .:36:0/039107 %08.3-0.08 08...44:9444:50020398-3.:79    .59078-.

0. 80.250314 2 0254008  0254000254000  84..:7 .

:7 3.84.. 80.203943$4-078.

20.3.

:7  ..025400 0254000254000  84. 80.

 80.:7 3.20488#4..84..

3.20.

025400 .

0254008 /05.792039 507843025/0 .

 507843025/0 .

 .

792039    ./05.

7308144 8 88908009   80 3.200254008 2..0.025400 :80025400.9.

 80. 80. 80 3.2084.9.. 2.025400 :8084.:7.

 .

88908009    .

9.:0 41 800.&8308144 8 89025.9 0 0254008 0  .902./05.792039  8..

3.20 .

:0 41 800. 8..9 0 0254008 025/ .

20 .3.

 .

90    .89025.

08419.39940307.914:..0883    .709.808 .38479200203994:9 97073$%47%574.0.90.7.4/3.20..08147%9900020398 4/44:2.3$%8908009 47  .980.

83.2085.8 83..0 .2085.8  238.0 ..8995...

.

842093.

8 708:9 57018.-4:8 8908009 5701.

9..902. 89025.

88908009 . .

.88908009 .

89025.90    .

.30942..55.00020398..$5....01742850.900020398 88975 85.30.0  -0900334/088:8:...7700.9438 9085.3//.01742.0$97553 32.39 88975 85..//7088.08975885..//7088/.10/0020398 $97585.90.

.00020398 ..0020398 88975 85.01742. $97585.

    .

0!70807..$5.394-0570807.00020398144-.079.0/  8570807...7.3 1.0 85.30020399508300/85.

    .

3.:95:9 .02039 .

:95:908.9573933:2-078    .759438 84:95:9..74:84:95:9459438  8/0. 1472.2.

07./.950 5:-.9.3/.07843329403 03. 80.4..4300834 /4.950 889028973 .7.943 002039863.84:95:9 ":.0  84:95:9 2094/2929094907 .9430834 89.8973 /4.208 3/0390834 20/. 9508973.4/38973 429 2 /0.

    .

3.02039 .7747 .

3/.943 &/.08 82088.4-4 89.55.943/0503/843..9082088.7/07747 410 819089349 .00307.08  !708039.088.

144.

.-.0 $477 4:300/.7  82088.

144.

-.7 .

0 .82088.

81    .

3/09 4:  84:/44147.$477 4:7$%574.0 9..-.002039 8144 81.9:70 .3//43 934494.381..-.-... 14:8008144.910.08847/4083 9..

 .-..81.

8144    .

8 995.47031472.943 $50.

.

  47.

%#.

89  995.

.

  47.

%#.

9 92 995.5.

.

  47.

%#.

89 .

995.

.

  47.

%#.

9 .5.

3 $0. :947  0333$% -03%033843 $%.0.0$%.3/!.389 995.2207 8#010703.0 -.07..44/-448 .9- 0342.9 3%0/0-03%033843 0139. $%!747.3/!.

.

42. -89 .

898.

8 89.

439.:5708.42    .9201478/08 5.4/ 309 55708..897./:8 .4/-.

Sign up to vote on this title
UsefulNot useful