Lecture Slides on XSLT - Distributed Software Develop | CS 682, Study notes of Software Engineering

Material Type: Notes; Class: Distributed Software Develop; Subject: Computer Science; University: University of San Francisco (CA); Term: Summer II 2005;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-d36
koofers-user-d36 🇺🇸

10 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Distributed Software Development
XSLT
Chris Brooks
Department of Computer Science
University of San Francisco
Department of Computer Science University of San Francisco p.1/??
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Lecture Slides on XSLT - Distributed Software Develop | CS 682 and more Study notes Software Engineering in PDF only on Docsity!

Distributed Software Development

XSLT Chris Brooks

Department of Computer ScienceUniversity of San Francisco

Department of Computer Science — University of San Francisco – p.1/

7-0:^ XSLT

XSLT is an XML-based language that allows you to declaratively

specify how a document should be changed or transformed.^ You specify the output for a particular element; no needto manage tree traversal. Useful for:^ Emitting an HTML display of an XML document^ Converting between tag vocabularies^ Extracting plain text from an XML document^ AUtomatically modifying or filtering an XML document.

Department of Computer Science — University of San Francisco – p.2/

7-2:^ Our CD database

</p> <p>Tomorrow</p> <p>Never^ Knows</p> <p>

Beatles

^

Revolver

^

Rock^

5

2:57^

6 ^ Feb^ ^2005 ...

Department of Computer Science — University of San Francisco – p.4/

7-3:^ Step 1: Using XSLT to emit plain

text

To begin, let’s use XSLT to print a plaintext version of ourcatalog. We can run XSLT from the command line or within abrowser.^ /usr/bin/4xslt on nexus^ Most modern browsers have XSLT support^ Debugging is easier from the command line

Department of Computer Science — University of San Francisco – p.5/

7-5:^ Emitting HTML

We can also emit other markup languages, such asHTML. (XHTML, actually). Just indicate the tags to be produced by a template match.

Department of Computer Science — University of San Francisco – p.7/

7-6:^ Emitting XML

We can also use XSLT to create new XML documentswith different tag names or contents. For example, let’s say we want to change the tags to be inSpanish.

Department of Computer Science — University of San Francisco – p.8/

7-8:^ Incorporating CSS

We can still use CSS to control presentational elements. With HTML, we can just embed a ’link’ tag in thegenerated HTML.

Department of Computer Science — University of San Francisco – p.10/

7-9:^ Incorporating CSS

If we’re emitting XML, we can instead embed a

processing

instruction

into the output document. Note: this will work best if we do the XSLT on the serverside.^ <xsl:processing-instruction

name="xml-stylesheet">

href="songs.css"

type="text/css"</xsl:processing-instruction>

Department of Computer Science — University of San Francisco – p.11/

7-11:^ Xpath

The examples we’ve seen so far match templates toelements based solely on the element’s tag name. Often, you want something more flexible:^ Match the root element^ Match all text nodes^ Match all children of an author node Essentially, we want to specify matching rules based onan element’s position in the DOM tree. XPath is a language for doing this.

Department of Computer Science — University of San Francisco – p.13/

7-12:^ XPath

In XPath, everything is dealt with as a path from the rootof the tree. To find a node, we’ll use a

location path

, which consists of

a series of

location steps

A location step consists of:^ An axis that tells us which direction to travel^ A node test that specifies which types of nodes apply^ predicates that use boolean tests to help filter nodes.

Department of Computer Science — University of San Francisco – p.14/

7-14:^ Node test

The second component of the location step is the nodetest. This is joined to the axis by a :: Some tests:^ / - root node^ * - any element^ author - any node named “author”^ text() - any text node In our Tolkien example, we might usebook/volumes/volume::”The Two Towers”

Department of Computer Science — University of San Francisco – p.16/

7-15:^ Shortcuts

// - descending from the root. //volume matches all volumenodes below the root. ../* - all siblings .. - parent /* - document element @name - matches attribute named ’name’

Department of Computer Science — University of San Francisco – p.17/

7-17:^ Predicates

If you need more flexibility in specifying nodes of interest,you can use a predicate. Predicates are contained inside square brackets. To be included in final node set, a node must pass bothaxis and predicate tests.

Department of Computer Science — University of San Francisco – p.19/

7-18:^ Examples

//song/[id=”s1”]/title/text - text for all ’s1’ songs. //song[title] - all quotations that have a source subelement. //song[not(source)] - songs that do not have a titlesub-element. //song[position() == 2] or //song[2] - the second quotation.

Department of Computer Science — University of San Francisco – p.20/