XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.
-
Upload
ashley-ross -
Category
Documents
-
view
280 -
download
3
Transcript of XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.
![Page 1: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/1.jpg)
XSLT I
Robin Burke
ECT 360
![Page 2: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/2.jpg)
Outline
XSLT processing XSLT syntax XPath XSLT basics Lab
![Page 3: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/3.jpg)
Admin
Announcement Milestone #4
![Page 4: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/4.jpg)
high-techentrepreneurshipnetworking event
Friday, October 21 5-7pm, CTI Collaboration Lab, Free
Surf to www.depaulcti.com for more information
Have you ever thought of using your IT skills to start your own company?
Join other CTI students and alumni in exploring the possibilities. e, CTI’s new high-tech entrepreneurship club invites you to an open house to mingle, network, and learn. We will present info on DePaul’s New Venture (business plan) Competition, with $5,000 in prizes – and help you find teammates. Refreshments served.
![Page 5: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/5.jpg)
XML
XSL "family" of standards
XSL-FO formatting objects typesetting document = a set of geometric areas organized on
pages XSLT
transformations XPath
supports both a language for addressing individual XML nodes
![Page 6: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/6.jpg)
XSL-FO Example
XMLdocument
XML-FOdocument
PDFdocument
XSLTstylesheet
XSLTengine
Renderingengine
![Page 7: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/7.jpg)
XSLT HTML example
XMLdocument
HTMLdocument
XSLTstylesheet
XSLTengine
Browser
![Page 8: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/8.jpg)
XSLT syntax
XML document stylesheet
root element templates
"rule-based" processing
![Page 9: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/9.jpg)
XSLT Processing
Let L be a list of nodes Let T be a list of templates style (L, T) =
Find a template t matching L• Instantiate t using L
• May call style (L', T)
• Return instantiated template To process a document
style ( { root }, T )
![Page 10: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/10.jpg)
Special purpose
XSLT is not a general-purpose programming languagelacks many conventional facilitiestechnically a "tree-rewriting" language
XSLT 2.0is more general purpose
![Page 11: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/11.jpg)
Example
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/><xsl:template match="/">
<html><head>
<title>Jeep suppliers</title></head><body>The first one is
<xsl:value-of select="/child::entries/child::entry[position() =
1]/child::address/child::name/child::text()" /></body></html>
</xsl:template></xsl:stylesheet>
![Page 12: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/12.jpg)
Note
stylesheet element output type element
![Page 13: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/13.jpg)
Running example
value-of1
![Page 14: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/14.jpg)
XPath
XPath expression"/child::entries/child::entry[position() =
1]/child::address/child::name/child::text()"
How to read "/" = root and delimiter for steps axis::step = a move in the XML document
• :: = "that is" or "that are" [] = apply some predicate position () = compute the position of this
element in its list of siblings text() = the element content
Result is a set of nodes
![Page 15: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/15.jpg)
Axes
self this node
child immediate descendant
descendant any descendant
attribute attribute list
following siblings to the right
preceding siblings to the left
![Page 16: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/16.jpg)
Steps
Depends on axis element name attribute name can be associated with a predicate
foo[attribute::bar='5']entry[position() = 2]
![Page 17: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/17.jpg)
XPath shortcuts
Axes can be abbreviated default = child @ = attribute // = descendant . = self .. = parent
Steps text() can be omitted [position() = n] can be [n]
Abbreviated version"/child::entries/child::entry[1]/child::address/child::name/child::text()""/entries/entry[1]/address/name"
![Page 18: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/18.jpg)
Example
with simplified syntax
![Page 19: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/19.jpg)
XML Document
entries
entry
address descrip
name line line phone
TEXTA & B
PerformanceAutomotive,
Inc.
TEXT20 FourthAvenue
TEXTHawthorne,NJ 07506
TEXT201-427-4464
TEXTEarly pickups and wagons;
has '45-87 Jeep parts
advertiser = "true"averageRating = "3.3" entry
address descrip
name line line phone
TEXTAJ's 4 WheelDrive Center
TEXT86 Guinter
Road
TEXTJersey Shore,
PA 17740
TEXT570-398-7520
TEXTFiberglass bodies and
accessories CJ-2A thruWrangler; one piece Wrangler
hood/fenders, tops
averageRating = "4.1"
web
TEXTwww.ajsjeepb
odies.com
![Page 20: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/20.jpg)
Paths
All "name" elements? All advertisers? All non-advertisers? The rating of the second entry? All advertisers with a rating above 3? The second line of every address?
![Page 21: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/21.jpg)
For-each
May want to operate on all nodes in a set
for-each elementinstantiates contents once for every
node in set
![Page 22: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/22.jpg)
Example
listing just names
![Page 23: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/23.jpg)
Multiple templates
Typically a stylesheet will have multiple templatesEasier to read / debugTemplates often correspond to
elementsMore modular
![Page 24: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/24.jpg)
Templates
template element match attribute
• describes nodes that use the template content
• template to instantiate apply-templates element
select attribute• what nodes to use
position shows where in the parent element the result is inserted
![Page 25: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/25.jpg)
Example
![Page 26: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/26.jpg)
Whitespace
XSLT automatically removes whitespacethis is often correctwhen it isn't
• use text element
![Page 27: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/27.jpg)
Path mismatch
Biggest source of errorsend path has no content
Check pathlocal pathtemplate matchapply-template select
Match/select should overlap by one step
![Page 28: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/28.jpg)
Example
template choice
![Page 29: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/29.jpg)
Building an element
<xsl:element name="a">
<xsl:attribute name="href">http://
<xsl:value-of select="." />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
Becomes
<a href="http://foo.org/">foo.org</a>
![Page 30: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/30.jpg)
Alternate syntax
<a href="http://{.}">
<xsl:value-of select="." /></a>
Becomes
<a href="http://foo.org/">foo.org</a>
![Page 31: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/31.jpg)
Sorting
We can sort node lists after they are selectedbefore they are operated onfor-eachapply-templates
Embed sort element
![Page 32: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/32.jpg)
Sorting, cont'd
<xsl:apply-templates select="some/path">
<xsl:sort select="whatever/@foo" />
</xsl:apply-templates>
What does this do?
![Page 33: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/33.jpg)
Example
complex selection and sorting
![Page 34: XSLT I Robin Burke ECT 360. Outline XSLT processing XSLT syntax XPath XSLT basics Lab.](https://reader035.fdocuments.net/reader035/viewer/2022081421/56649ec15503460f94bcc607/html5/thumbnails/34.jpg)
Break / Lab