XSL Stylesheet 1 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

XSL Stylesheet 1

Description:

If you don't understand the meaning of this, think of XSL as a ... Greatest Hits Dolly Parton. 11. L. Khan, UTD. XML (eXtensible Markup Language) bib ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 18
Provided by: cyrussh
Category:
Tags: xsl | dolly | parton | stylesheet

less

Transcript and Presenter's Notes

Title: XSL Stylesheet 1


1
XSL Stylesheet (1)
  • XSL - More than a Style Sheet
  • XSL consists of three parts
  • a method for transforming XML documents
  • a method for defining XML parts and patterns
  • a method for formatting XML documents
  • If you don't understand the meaning of this,
    think of XSL as a language that can transform XML
    into HTML, a language that can filter and sort
    XML data, a language that can address parts of an
    XML document, a language that can format XML data
    based on the data value, like displaying negative
    numbers in red, and a language that can output
    XML data to different devices, like screen, paper
    or voice. 

2
XSL Stylesheet (2)
  • XSL - The Style Sheet of XML
  • Because XML does not use predefined tags (we can
    use any tags we want), the meanings of these tags
    are not understood could mean an HTML
    table or maybe a piece of furniture. Because of
    the nature of XML, the browser does not know how
    to display an XML document.
  • In order to display XML documents, it is
    necessary to have a mechanism to describe how the
    document should be displayed. One of these
    mechanisms is CSS, but XSL (the eXtensible
    Stylesheet Language) is the preferred style sheet
    language of XML, and XSL is far more
    sophisticated than the CSS used by HTML.

3
A Simple XSL Stylesheet
  • How to transform XML into HTML using XSL Start
    with your XML Document
  • First you start with the XML document that you
    want to transform into HTML
  • Empire Burlesque
  • Bob Dylan
  • USA
  • Columbia
  • 10.90
  • 1985
  • . . .

4
A Less Simple XSL Stylesheet
  • -xsl"
  • Title
  • Artist


5
A Less Simple XSL Stylesheet (Cont.)
  • Link the Style Sheet to the XML document
  • Then you add an XSL Style Sheet reference to your
    XML document
  • href"cd_catalog.xsl"?
  • Empire Burlesque
  • Bob Dylan
  • USA
  • Columbia
  • 10.90 1985 . .
    .
  • If you have an XSL compliant browser, like
    Internet Explorer 5.0 or later, your browser will
    nicely transform your XML into HTML.

6
A Less Simple XSL Stylesheet (Cont.)
  • XSL uses Templates XSL uses one or more
    templates to define how to output XML elements. A
    match attribute is used to associate the template
    with an XML element. (The match attribute can
    also be used to define a template for a whole
    branch of the XML document).
  • Look at the following XSL Style Sheet that
    contains a template to output the XML CD Catalog
    from the previous example
  • -xsl"
  • Title Artist
  • .
  • .


7
A Less Simple XSL Stylesheet (Cont.)
  • Since the style sheet is an XML document itself,
    the document begins with an xml declaration
  • The xslstylesheet tag in the second line defines
    the start of the stylesheet.
  • The xsltemplate tag in the third line defines
    the start of a template. The template attribute
    match"/" associates (matches) the template to
    the root (/) of the XML source document.
  • The rest of the document contains the template
    itself, except for the last two lines that
    defines the end of the template and the end of
    the style sheet.
  • The result of the transformation will look (a
    little disappointing) like this
  • Title Artist
  • . .

8
A Less Simple XSL Stylesheet (Cont.)
  • The Element
  • The result from the previous sample was a little
    disappointing, because no data was copied from
    the XML document to the output.
  • The XSL element can be used to
    select XML elements into the output stream of the
    XSL transformation
  • -xsl"
  • border"1"
  • Title Artist


  • Note the syntax for the select attribute value
    is called an XSL Pattern. It works like
    navigating a file system where a forward slash
    (/) selects subdirectories.

9
A Less Simple XSL Stylesheet (Cont.)
  • The result of the transformation will look like
    this
  • Title Artist
  • Empire Burlesque Bob Dylan
  • The Element The result from the
    previous sample was a also a little
    disappointing, because only one line of data was
    copied from the XML document to the output.
  • The XSL element can be used to
    select every XML element into the output stream
    of the XSL transformation
  • -xsl"
  • Title

10
A Less Simple XSL Stylesheet (Cont.)
  • Artist

  • The xslfor-each element locates elements in the
    XML document and repeats a part of the template
    for each one.
  • The result of the transformation will look like
    this
  • Title Artist
  • Empire Burlesque Bob Dylan
  • Hide your heart Bonnie Tyler
  • Greatest Hits Dolly Parton

11
XML(eXtensible Markup Language)
TCP/IP
Illustrated
Stevens
W.
Addison Wesley
65.95 year"1992"
12
XQuery Example 1
Get title of books published by Addison-Wesley in
1994.
FOR b IN document("bib.xml")/bib/book WHERE
b/publisher "Addison-Wesley" AND b/_at_year
"1994" RETURN b/title
TCP/IP Illustrated
13
FLWR Expressions
  • Basic FLWR Expression
  • For -- consider (introduce a variable)
  • Let -- introduce additional variables
  • Where -- filter by conditions
  • Return -- build results
  • Xquery is compositional any place data can go,
    another FLWR expression can go.

14
XQuery Example 2
Get title of books published in 1994.
FOR b IN document("bib.xml")/bib/book LET c
b/publisher WHERE c "Addison-Wesley" AND
b/_at_year "1994" RETURN b/title
TCP/IP Illustrated
15
XQuery Example 3
Join and on and print the
title and price.
FOR b IN document("bib.xml")/bib/book FOR e
IN document("reviews.xml")/reviews/entry
WHERE e/title b/title RETURN
b/title, e/price

Data on the Web
34.95
16
XQuery Example 4
Get the average price of the books.
LET prices document("bib.xml")/bib/
book/price RETURN avg(prices)

75.45
17
XQuery Example 5
Get year (as an attribute) and title of book.
(Use a predicate to Limit the books to those
published by Addison-Wesley.)
FOR b IN document("bib.xml")/bib/book FOR c
IN bpublisher "Addison-Wesley" RETURN
c/_at_year c/title
TCP/IP
Illustrated
Advanced Programming in the Unix
environment
Write a Comment
User Comments (0)
About PowerShow.com