


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 / 4
This page cannot be seen from the preview
Don't miss anything!



Chris Brooks Department of Computer Science University of San Francisco ?? Department of Computer Science — University of San Francisco – p.1/
XSLT is an XML-based language that allows you to specify how a document should be changed declaratively or transformed. You specify the output for a particular element; no need to 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/
You can transform an XML document into: Plain text
XML (or any flavor thereof) ?? Department of Computer Science — University of San Francisco – p.3/
To begin, let’s use XSLT to print a plaintext version of our catalog. We can run XSLT from the command line or within a browser. /usr/bin/4xslt on nexus Most modern browsers have XSLT support Debugging is easier from the command line
That’s fine, but pretty dull. Let’s select just artist, title, and album to display. We do that through the use of apply-templates. What if we left out apply-templates in the song template?
We can also emit other markup languages, such as HTML. (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 documents with different tag names or contents. For example, let’s say we want to change the tags to be in Spanish. ?? Department of Computer Science — University of San Francisco – p.8/
When transforming from XML to XML, often, it’s useful to copy sections of a document without changing it. copy makes a shallow copy of a node. Useful if you want to change a bunch of values or attributes. copy-of makes a deep copy and lets you specify a path. For example, let’s make a new database with just artist, album and title. ?? Department of Computer Science — University of San Francisco – p.9/
We can still use CSS to control presentational elements. With HTML, we can just embed a ’link’ tag in the generated HTML. ?? Department of Computer Science — University of San Francisco – p.10/
processing If we’re emitting XML, we can instead embed a into the output document. instruction Note: this will work best if we do the XSLT on the server side. name="xml-stylesheet"> <xsl:processing-instruction type="text/css"</xsl:processing-instruction> href="songs.css"
The command line is great for debugging, but much of the time, we want the client to do the work. Most web browsers have at least some support for XSLT. More advanced features are not universally supported. In particular, the browser’s XSLT processor may make a single pass and not apply the CSS. (firefox)
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 both axis 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 title sub-element. //song[position() == 2] or //song[2] - the second quotation. ?? Department of Computer Science — University of San Francisco – p.20/
XPath is very useful for allowing users to query an XML document. Even more useful for specifying which transformations should be applied in an XML document. gives us a way to easily specify transformations that should take place based on a node’s context. ?? Department of Computer Science — University of San Francisco – p.21/
XSLT also has built-in support for sorting and processing your elements. ?? Department of Computer Science — University of San Francisco – p.22/
You can also pass paramters into an XSLT stylesheet. You can also define them at the top of your XSLT program. Parameters can be referenced with a $. select="0.10"/> name="discount" <xsl:param ... select="$discount"/>
The DOM API makes it easy to create new Nodes for an existing document.