
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Distributed Software Develop; Subject: Computer Science; University: University of San Francisco (CA); Term: Summer II 2005;
Typology: Study notes
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















Department of Computer ScienceUniversity of San Francisco
Department of Computer Science — University of San Francisco – p.1/
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/
Tomorrow
Never^ Knows
Beatles
Revolver
Rock^
5
2:57^
6
Department of Computer Science — University of San Francisco – p.4/
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/
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/
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/
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/
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/
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/
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/
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/
// - 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/
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/
//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/