XSL - PowerPoint PPT Presentation

About This Presentation
Title:

XSL

Description:

artist Pink Floyd /artist price 10.90 /price /cd cd country='UK' ... Pink Floyd. David Bowie. Aretha Franklin. 10.90. 9.90. 9.90 /catalog/cd/price ... – PowerPoint PPT presentation

Number of Views:105
Avg rating:3.0/5.0
Slides: 85
Provided by: csHu
Category:
Tags: xsl | floyd | pink

less

Transcript and Presenter's Notes

Title: XSL


1
XSL XML Stylesheet Language
2
XSL
  • XSL XML Stylesheet Language
  • XSL cosists of
  • XPath (navigation in documents)
  • XSLT (T for transformations)
  • XSLFO (FO for formatting objects)
  • This is a rather complex language for typesetting
    (i.e., preparing text for printing)
  • It will not be taught

3
XPath
  • A Language for Locating Nodes
  • in XML Documents

4
XPath
  • XPath expressions are written in a syntax that
    resembles paths in file systems
  • The list of nodes located by an XPath expression
    is called a Nodelist
  • XPath is used in XSL and in XQuery (a query
    language for XML)
  • W3Schools has an XPath tutorial
  • XPath includes
  • Axis navigation
  • Conditions
  • Functions

5
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltcatal
oggt ltcd country"UK"gt lttitlegtDark
Side of the Moonlt/titlegt ltartistgtPink
Floydlt/artistgt ltpricegt10.90lt/pricegt
lt/cdgt ltcd country"UK"gt
lttitlegtSpace Odditylt/titlegt
ltartistgtDavid Bowielt/artistgt
ltpricegt9.90lt/pricegt lt/cdgt ltcd
country"USA"gt lttitlegtAretha Lady
Soullt/titlegt ltartistgtAretha
Franklinlt/artistgt ltpricegt9.90lt/pricegt
lt/cdgt lt/cataloggt
An XML document
6
catalog.xml
The XML document as a DOM tree
catalog
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
7
The Main Idea in the Syntax of XPath Expressoins
  • / at the beginning of an XPath expression
    represents the root of the document
  • / between element names represents a
    parent-child relationship
  • // represents an ancestor-descendent
    relationship
  • _at_ marks an attribute
  • condition specifies a condition

8
catalog.xml
catalog
/catalog
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
Getting the root element of the document
9
catalog.xml
catalog
/catalog/cd
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
Finding child nodes
10
catalog.xml
catalog
/catalog/cd/price
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
Finding descendent nodes
11
catalog.xml
catalog
/catalog/cdpricelt10
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
Condition on elements
12
catalog.xml
/catalog//title
catalog
//title
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
// represents any directed path in the document
13
catalog.xml
catalog
/catalog/cd/
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
represents any element name in the document
14
//
catalog.xml
What will the following expressions return?
//
catalog
//price9.90
//price9.90/
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
represents any element name in the document
15
catalog.xml
/catalog/cd1
catalog
/catalog/cdlast()
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
Position based condition
16
catalog.xml
/catalog/cd_at_countryUK
catalog
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
_at_ marks attributes
17
catalog.xml
catalog
/catalog/cd/_at_country
cd
cd
country
cd
country
country
USA
UK
UK
title
artist
price
title
artist
price
title
artist
price
Space Oddity
Aretha Lady Soul
Dark Side of the Moon
David Bowie
Aretha Franklin
Pink Floyd
9.90
9.90
10.90
_at_ marks attributes
18
Relative Navigation Using Axes
  • Starts with the current node and not with the
    root (/)
  • A . marks the current node (e.g., ./title)
  • A .. marks the parent node (e.g., title/../)
  • There are also other axes, e.g., child,
    descendent, ancestor, parent, following-sibling,
    etc.

19
Functions
  • Many functions that are included in XPath
  • Some examples
  • count() returns the number of nodes in a
    nodelist
  • last() returns the last node in a nodelist
  • name() returns the name of a node
  • position() returns the position of the node in
    the nodelist

20
Additional Examples ofXPath Expressions
  • These examples use element names that are not
    necessarily from the XML document that was shown
    previously

21
Examples of XPath Expressions
  • para
  • Selects the para children elements of the context
    node
  • Selects all element children of the context node
  • text()
  • Selects all text node children of the context
    node
  • _at_name
  • Selects the name attribute of the context node

22
More Examples ofXPath Expressions
  • _at_
  • Selects all the attributes of the context node
  • para1
  • Selects the first para child of the context node
  • paralast()
  • Selects the last para child of the context node
  • /para
  • Selects all para grandchilren of the context node

23
More Examples ofXPath Expressions
  • /doc/chapter5/section2
  • Selects the second section of the fifth chapter
    of the doc
  • chapter//para
  • Selects the para element descendants of the
    chapter element children of the context node
  • //para
  • Selects all the para descendants of the document
    root and thus selects all para elements in the
    same document as the context node

24
More Examples ofXPath Expressions
  • //olist/item
  • Selects all the item elements that have an olist
    parent and are in the same document as the
    context node
  • .
  • Selects the context node
  • .//para
  • Selects the para descendants of the context node
  • ..
  • Selects the parent of the context node

25
More Examples ofXPath Expressions
  • ../_at_lang
  • Selects the lang attribute of the parent of the
    context node
  • para_at_typewarning
  • Selects the para children of the context node
    that have a type attribute with value warning
  • chaptertitle
  • Selects the chapter children of the context node
    that have one or more title children

26
More Examples ofXPath Expressions
  • para_at_typewarning5
  • Selects the fifth para child among the children
    of the context node that have a type attribute
    with value warning
  • para5_at_typewarning
  • Selects the fifth para child of the context node
    if that child has a type attribute with value
    warning

27
More Examples ofXPath Expressions
  • chaptertitleIntroduction
  • Selects the chapter children of the context node
    that have one or more title children with
    string-value equal to Introduction
  • employee_at_secretary and _at_assistant
  • Selects employee children of the context node
    that have both a secretary attribute and an
    assistant attribute

28
More Examples of Xpath Expressions
  • /university/department/course
  • This Xpath expression matches any path that
    starts at the root, which is a university
    element, passes through a department element and
    ends in a course element
  • ./department/course_at_year2002
  • This Xpath expression matches any path that
    starts at the current element, continues to a
    child which is a department element and ends at
    a course element with a year attribute that is
    equal to 2002

29
Location Paths
  • The previous examples are abbreviations of
    location paths
  • See XPath tutorial in W3Schools or Costellos
    slides on long names
  • For example, // is short for /descendant-or-self
    node()/.
  • //para is short for
    /descendant-or-selfnode()/childpara

30
XSLT
  • Transforming XML documents into other XML
    documents

31
XSLT Stylesheet
  • An XSLT stylesheet is a program that transforms
    an XML document into another XML document
  • For example
  • Transforming XML to XHTML (HTML that conforms to
    XML syntax)
  • Transforming an XML document to WML (a format of
    XML that cellular phones can display)

32
A Few Things About XSL
  • XSL is a high-level, functional language
  • The syntax is a bit peculiar and possibly
    confusing
  • An XSL style sheet is a valid XML document
  • Valid with respect to the XSL namespace
  • Therefore, commands in XSL are XSL elements

33
Applying XSLT Stylesheets toXML Documents
  • There are three ways of applying an XSLT
    stylesheet to an XML document
  • Directly applying an XSLT processor to the XML
    document and the XSLT stylesheet
  • Calling an XSLT processor from within a (Java)
    program
  • Adding to the XML document a link to the XSL
    stylesheet and letting the browser do the
    transformation

34
Using an XSL Processor
XSL stylesheet
XML document
Result is either an XML, HTML or text document
XSL Processor
35
Letting a Browser Perform the Transformation
lt?xml version"1.0" encoding"ISO-8859-1"?gt lt?xml-
stylesheet type"text/xsl" hrefcatalog.xsl"?gt
ltcataloggt ltcd country"UK"gt
lttitlegtDark Side of the Moonlt/titlegt
ltartistgtPink Floydlt/artistgt
ltpricegt10.90lt/pricegt lt/cdgt lt/cataloggt
36
The Root of the XSL Document
  • The Root of the XSL document should be one of the
    following lines

ltxslstylesheet version"1.0" xmlnsxsl"http//w
ww.w3.org/1999/XSL/Transform"gt
ltxsltransform version"1.0" xmlnsxsl"http//ww
w.w3.org/1999/XSL/Transform"gt
The namespace allows the XSL processor to
distinguish between XSL tags and tags of the
result document
37
How Does XSLT Work?
  • An XSL stylesheet is a collection of templates
    that are applied to source nodes (i.e., nodes of
    the given XML document)
  • Each template has a match attribute that
    specifies to which source nodes the template can
    be applied
  • The current source node is processed by applying
    a template that matches this node
  • Processing always starts at the root (/)

38
Templates
  • A template has the form
  • ltxsltemplate match"pattern"gt
  • ...
  • lt/xsltemplategt
  • The content of a template consists of
  • XML elements and text that are copied to the
    result
  • XSL elements that are actually instructions
  • The pattern syntax is a subset of XPath

39
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt lth1gtHello
Worldlt/h1gt lt/bodygt lt/htmlgt lt/xsltemplategt lt/xs
lstylesheetgt
40
lthtmlgt ltbodygt lth1gtHello Worldlt/h1gt lt/bodygt lt/htmlgt
Applying a browser to catalog.xml (catalog.xml
has a link to catalog.xsl)
41
The Elementltxslapply-templatesgt
  • Processing starts by applying a template that
    matches the root (/)
  • If the given XSL stylesheet does not have a
    template that matches the root, then one is
    inserted by default (see the slide on Default
    Templates)
  • The XSL stylesheet must specify explicitly
    whether templates should be applied to
    descendants of the root
  • It is done by putting inside a template the
    instruction
  • ltxslapply-templates select"xpath"/gt
  • Without the select attribute, this instruction
    processes all the children of the current node

42
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.
org/1999/XSL/Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt ltxslapply-templates
select"catalog/cd"/gt lt/bodygt
lt/htmlgt lt/xsltemplategt ltxsltemplate
match"cd"gt lth2gtA CD!lt/h2gt lt/xsltemplategt lt/
xslstylesheetgt
lthtmlgt ltbodygt lth2gtA CD!lt/h2gt lth2gtA CD!lt/h2gt
lth2gtA CD!lt/h2gt lt/bodygt lt/htmlgt
43
Default Templates
  • XSL provides implicit built-in templates that
    match every element and text nodes
  • Templates we write always override these built-in
    templates (when they match)

ltxsltemplate match/ gt ltxslapply-templates
/gt lt/xsltemplategt ltxsltemplate
matchtext()gt ltxslvalue-of select./gt lt/xsl
templategt
44
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
matchcdtitleSpace Oddity"gt lthtmlgt
ltbodygt lth1gtHello Worldlt/h1gt lt/bodygt
lt/htmlgt lt/xsltemplategt lt/xslstylesheetgt
What is generated when this xsl is applied to
catalog.xml?
45
Dark Side of the Moon Pink Floyd
10.90 lthtmlgtltbodygtlth1gtHello
Worldlt/h1gtlt/bodygtlt/htmlgt Aretha Lady
Soul Aretha Franklin 9.90
46
The Most Frequently Used Elements of XSL
  • ltxslvalue-of selectxpath-expression/gt
  • This element extracts the value of a node from
    the nodelist located by xpath-expression
  • ltxslfor-each selectxpath-expression/gt
  • This element loops over all the nodes in the
    nodelist located by xpath-expression
  • ltxslif testxpath-expression/gt,
    ltxslif testxpath-expressionvalue/gt, etc.
  • This element is for conditional processing

47
The ltxslvalue-ofgt Element
ltxslvalue-of selectxpath-expression/gt
  • The XSL element ltxslvalue-ofgt can be used to
    extract the value of an element that is selected
    from the source XML document
  • The extracted value is added to the output stream
  • The selected element is located by an XPath
    expression that appears as the value of the
    select attribute

48
Selected values
49
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt lth2gtA CD
Cataloglt/h2gt lttable border"1"gt lttr
bgcoloryellow"gt ltthgtTitlelt/thgt
ltthgtArtistlt/thgt lt/trgt
50
lttrgt lttdgtltxslvalue-of select"catalog/cd
/title"/gt lt/tdgt lttdgtltxslvalue-of
select"catalog/cd/artist"/gt lt/tdgt
lt/trgt lt/tablegt lt/bodygt lt/htmlgt lt/xsltemplate
gt lt/xslstylesheetgt
Note that only the first matched element is
retrieved for each ltxslvalue ofgt
51
The ltxslfor-eachgt Element
ltxslfor-each selectxpath-expression/gt
  • The ltxslfor-eachgt element loops over all the
    nodes in the nodelist of the XPath expression
    that appears as the value of the select attribute
  • The value of each node can be extracted by an
    ltxslvalue-ofgt element

52
All the values are selected
53
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt lth2gtA CD
Cataloglt/h2gt lttable border"1"gt lttr
bgcoloryellow"gt ltthgtTitlelt/thgt
ltthgtArtistlt/thgt lt/trgt
As in the previous example
54
ltxslfor-each select"catalog/cd"gt lttrgt
lttdgtltxslvalue-of select"title"/gt
lt/tdgt lttdgtltxslvalue-of
select"artist"/gt lt/tdgt lt/trgt
lt/xslfor-eachgt lt/tablegt lt/bodygt
lt/htmlgt lt/xsltemplategt lt/xslstylesheetgt
Note that all the /catalog/cd elements are
retrieved
55
Consider the following change in the select
attribute
ltxslfor-each select"catalog/cdpricelt10
"gt lttrgt lttdgtltxslvalue-of
select"title"/gt lt/tdgt
lttdgtltxslvalue-of select"artist"/gt lt/tdgt
lt/trgt lt/xslfor-eachgt lt/tablegt
lt/bodygt lt/htmlgt lt/xsltemplategt lt/xslstylesheet
gt
Only elements that satisfy /catalog/cdpricelt10
are retrieved
56
(No Transcript)
57
The ltxslsortgt Element
  • The ltxslsortgt element is used to sort the list
    of nodes that are looped over by the
    ltxslfor-eachgt element
  • Thus, the ltxslsortgt must appear inside the
    ltxslfor-eachgt element
  • The looping is done in sorted order

58
Sorted by the name of the artist
59
ltxslfor-each select"catalog/cd"gt ltxslsort
select"artist"/gt lttrgt
lttdgtltxslvalue-of select"title"/gt lt/tdgt
lttdgtltxslvalue-of select"artist"/gt lt/tdgt
lt/trgt lt/xslfor-eachgt lt/tablegt
lt/bodygt lt/htmlgt lt/xsltemplategt lt/xslstylesheet
gt
The /catalog/cd elements are sorted according to
the value of the artist element
60
The ltxslifgt Element
  • The ltxslifgt element is used for conditional
    processing
  • The condition appears as the value of the test
    attribute, for example
  • ltxslif test"price gt 10"gt  some output
    ...lt/xslifgt
  • The elements inside the ltxslifgt element are
    processed if the condition is true

61
Note
  • Processing the inside elements means
  • Copying them into the output stream if they are
    not XSL elements, and
  • Evaluating them if they are XSL elements
  • If the value of the test attribute is just an
    XPath expression (i.e., without any comparison),
    then the test is satisfied if the nodelist of
    this XPath expression is not empty

62
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt lth2gtA CD
Cataloglt/h2gt lttable border"1"gt lttr
bgcoloryellow"gt ltthgtTitlelt/thgt
ltthgtArtistlt/thgt lt/trgt
As in the previous examples
63
ltxslfor-each select"catalog/cd"gt ltxslif
test"price gt 10"gt lttrgt
lttdgtltxslvalue-of select"title"/gt lt/tdgt
lttdgtltxslvalue-of select"artist"/gt lt/tdgt
lt/trgt lt/xslifgt lt/xslfor-eachgt
lt/tablegt lt/bodygt lt/htmlgt lt/xsltemplategt lt/xs
lstylesheetgt
Only /catalog/cd with pricegt10 are retrieved
64
(No Transcript)
65
Question
  • In the previous example, what should be the
    condition if we want to extract the information
    for all cds that have a price (i.e., the
    information about the price is not missing)?

66
The ltxslchoosegt Element
  • The ltxslchoosegt element is used in conjunction
    with ltxslwhengt and ltxslotherwisegt to express
    test with multiple conditions
  • There can be many ltxslwhengt inside an
    ltxslchoosegt element, but there should be a
    single ltxslotherwisegt inside an ltxslchoosegt
    element

67
Using ltxslchoosegt
  • To insert a conditional choose against the
    content of the XML file, simply add the
    ltxslchoosegt, ltxslwhengt, and ltxslotherwisegt
    elements to your XSL document like this
  • ltxslchoosegt   ltxslwhen test"price gt
    10"gt      ... some code ...   lt/xslwhengt  
    ltxslotherwisegt      ... some code ....  
    lt/xslotherwisegtlt/xslchoosegt

68
ltxslfor-each select"catalog/cd"gtlttrgt
lttdgtltxslvalue-of select"title"/gtlt/tdgt
ltxslchoosegt ltxslwhen test"price gt 10"gt
lttd bgcolor"red"gt ltxslvalue-of
select"artist"/gtlt/tdgt lt/xslwhengt
ltxslwhen test"pricegt9 and pricelt10"gt
lttd bgcolor"gray"gt
ltxslvalue-of select"artist"/gtlt/tdgt
lt/xslwhengt ltxslotherwisegt
lttdgtltxslvalue-of select"artist"/gtlt/tdgt
lt/xslotherwisegt lt/xslchoosegtlt/trgt lt/xslfor-ea
chgt
69
(No Transcript)
70
Applying Templates Recursively
  • The following example shows how to apply
    templates recursively
  • Generally, it is possible (but not in this
    example) that more than one template matches the
    current source node
  • The specification (www.w3.org/TR/xslt) describes
    (Section 5.5) which template should be chosen for
    application

71
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet version"1.0" xmlnsxsl"http//www.w3.o
rg/1999/XSL/ Transform"gt ltxsltemplate
match"/"gt lthtmlgt ltbodygt lth2gtA CD
Cataloglt/h2gt ltxslapply-templates/gt
lt/bodygt lt/htmlgt lt/xsltemplategt
72
ltxsltemplate match"cd"gt ltpgt
ltxslapply-templates select"title"/gt
ltxslapply-templates select"artist"/gt
lt/pgt lt/xsltemplategt ltxsltemplate
match"title"gt Title ltspan style"colorred"gt
ltxslvalue-of select"."/gtlt/spangt ltbr
/gt lt/xsltemplategt
73
ltxsltemplate match"artist"gt Artist ltspan
style"colorgreen"gt ltxslvalue-of
select"."/gtlt/spangt ltbr /gt lt/xsltemplategt lt/xs
lstylesheetgt
74
(No Transcript)
75
Is Recursive Application of Templates Really
Needed?
  • The output of the previous example can also be
    generated by an XSL stylesheet that uses only one
    template that matches the root (and does not use
    the element ltxslapply-templatesgt)
  • However, some tasks can only be done by applying
    templates recursively
  • This typically happens when the structure of the
    source XML document is not known

76
For example
  • Suppose that we want to write an XSL stylesheet
    that generates an exact copy of the source XML
    document
  • It is rather easy to do it when the structure of
    the source XML document is known
  • Can we write an XSL stylesheet that does it for
    every possible XML document?
  • Yes! (see next slide)

77
lt?xml version"1.0"?gt ltxslstylesheet
xmlnsxsl"http//www.w3.org/1999/XSL/Transform"
version"1.0"gt ltxsloutput
method"xml"/gt ltxsltemplate match""gt
ltxslelement name"name(.)"gt
ltxslfor-each select"_at_"gt
ltxslattribute name"name(.)"gt
ltxslvalue-of select"."/gt
lt/xslattributegt lt/xslfor-eachgt
ltxslapply-templates/gt
lt/xslelementgt lt/xsltemplategt lt/xslstyleshe
etgt
Identity Transformation Stylesheet
78
The ltxsloutputgt Element

lt?xml version"1.0" encoding"ISO-8859-1"?gt
ltxslstylesheet version"1.0" xmlnsxsl"http//
www.w3.org/1999/XSL/ Transform"gt ltxsloutput
method"xml" version"1.0" encoding"iso-8859-1"
indent"yes"/gt ...... lt/xslstylesheetgt
Tells in what format the output should be
xml/html/text
79
Some Other XSL Elements
  • The ltxsltextgt element allows to insert free text
    in the output
  • The ltxslcopy-ofgt element creates a copy of the
    current node
  • The ltxslcommentgt element is used to create a
    comment node in the result tree
  • There are more elements and functions look in
    the specification! (www.w3.org/TR/xslt)

80
Costellos Tutorial(See DBI Lecture Schedule for
a reference)
  • Costello has an excellent and detailed tutorial
  • First part (xsl01.ppt) has many examples that do
    not use recursion
  • Second part (xsl02.ppt) explains how to use
    recursion and why it is needed (the identity
    transformation shown earlier is from Costellos
    tutorial)

81
W3Schools Tutorial on XSLT
  • The W3Schools XSLT Tutorial has (among other
    things) tables that list all the elements and
    functions of XSLT
  • It also has some details about implementations
  • Some browsers may not implement all features or
    may implement some features differently from the
    specifications

82
How to Use the Examples
  • Since XSL is a high-level language, XSLT
    stylesheets are relatively short and easy to
    understand
  • It is easy to modify an existing style- sheet
    into another stylesheet with a similar
    functionality
  • The many examples of Costello and W3Schools are
    very useful as a starting point for writing your
    own stylesheets

83
Summary
  • XSLT is a high-level transformation language
  • Create core output once in XML format (using
    Servlets, JSP, etc.)
  • Use XSLT to transform the core output as needed

84
For Example
  • Suppose that you have produced an XML catalog of
    products
  • Now you decide to lower all prices by 10
  • It is easy to do it in XSLT
  • Modify the identity transformation to do that
Write a Comment
User Comments (0)
About PowerShow.com