XSLT and XPath - Advance Java Web Technology - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advance Java Web Technology which includes Extensible Stylesheet Language, Styling HTML Pages, Xsl Transformations, Xsl Formatting Objects, XML Source Document, Transformed Information, Simple Xpath, Titles and Authors etc. Key important points are: Xslt and Xpath, Extensible Stylesheet Language, Styling HTML Pages, Xsl Transformations, Xsl Formatting Objects, XML Source Document, Transformed Information, Simple Xpath, Titles and Authors

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
XSL
XSLT and XPath
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download XSLT and XPath - Advance Java Web Technology - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

XSL

XSLT and XPath

What is XSL?

  • XSL stands for Extensible Stylesheet Language
  • CSS was designed for styling HTML pages, and can be used to style XML pages
  • XSL was designed specifically to style XML pages, and is much more sophisticated than CSS
  • XSL consists of three languages:
    • XSLT (XSL Transformations) is a language used to transform XML documents into other kinds of documents (most commonly HTML, so they can be displayed)
    • XPath is a language to select parts of an XML document to transform with XSLT
    • XSL-FO (XSL Formatting Objects) is a replacement for CSS
      • There are no current implementations of XSL-FO, and we won’t cover it

Simple XPath

  • Here’s a simple XML document:
 XML Gregory Brill Java and XML Brett McLaughlin - XPath expressions look a lot like paths in a computer file system - / means the document itself (but no specific elements) - /library selects the root element - /library/book selects _every_ book element - //author selects _every_ author element, wherever it occurs 

Simple XSLT

• loops through

every book element, everywhere in the

document

• chooses the

content of the title element at the current

location

chooses the content of the title element for each

book in the XML document

What we need to do

• We need to save our XML into a file (let’s call it

books.xml)

• We need to create a file (say, books.xsl) that

describes how to select elements from

books.xml and embed them into an HTML page

  • We do this by intermixing the HTML and the XSL in the

books.xsl file

• We need to add a line to our books.xml file to

tell it to refer to books.xsl for formatting

information

books.xml, revised

  •  XML Gregory Brill Java and XML Brett McLaughlin 

This tells you where to find the XSL file

XSL outline

...

Selecting titles and authors

Book titles:

Book authors: ...same thing, replacing title with author

 Notice that XSL can rearrange the data; the HTML result can present information in a different order than the XML

Notice the xsl:for-each loop

All of books.xsl

Book Titles and Authors

Book titles:

Book authors:

How to use it

• In a modern browser, such as Netscape 6,

Internet Explorer 6, or Mozilla 1.0, you can just

open the XML file

  • Older browsers will ignore the XSL and just show

you the XML contents as continuous text

• You can use a program such as Xalan, MSXML,

or Saxon to create the HTML as a file

  • This can be done on the server side, so that all the

client side browser sees is plain HTML

  • The server can create the HTML dynamically from

the information currently in XML

The End