DOC PREVIEW
USF CS 682 - Distributed Software Development

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

{small lecturenumber - hepage :} XSLT{small lecturenumber - hepage :} Output{small lecturenumber - hepage :} Our CD database{small lecturenumber - hepage :} Step 1: Using XSLT to emit plain text{small lecturenumber - hepage :} Step 2: filtering elements{small lecturenumber - hepage :} Emitting HTML{small lecturenumber - hepage :} Emitting XML{small lecturenumber - hepage :} Copying Nodes{small lecturenumber - hepage :} Incorporating CSS{small lecturenumber - hepage :} Incorporating CSS{small lecturenumber - hepage :} Referencing a stylesheet from an XML document{small lecturenumber - hepage :} Xpath{small lecturenumber - hepage :} XPath{small lecturenumber - hepage :} Axes{small lecturenumber - hepage :} Node test{small lecturenumber - hepage :} Shortcuts{small lecturenumber - hepage :} Examples{small lecturenumber - hepage :} Predicates{small lecturenumber - hepage :} Examples{small lecturenumber - hepage :} So what's all this good for?{small lecturenumber - hepage :} Sorting{small lecturenumber - hepage :} Parameters in XSLT{small lecturenumber - hepage :} Using XSLT from Python{small lecturenumber - hepage :} SummaryDistributed Software DevelopmentXSLTChris BrooksDepartment of Computer ScienceUniversity of San FranciscoDepartment of Computer Science — University of San Francisco – p. 1/??9-2: XSLT•XSLT is an XML-based language that allows you todeclaratively specify how a document should be changed ortransformed.◦You specify the output for a particular element; no need tomanage 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/??9-3: Output•You can transform an XML document into:◦Plain text◦HTML◦XML (or any flavor thereof)Department of Computer Science — University of San Francisco9-4: Our CD database<catalog><song><title> Tomorrow Never Knows </title><artist> Beatles </artist><album> Revolver </album><genre> Rock </genre><rating> 5 </rating><length> 2:57 </length><date><day> 6 </day><month> Feb </month><year> 2005 </year></date></song>...</catalog>Department of Computer Science — University of San Francisco – p. 4/??9-5: 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 a browser.◦/usr/bin/4xslt on lab machines◦Most modern browsers have XSLT support◦Debugging is easier from the command lineDepartment of Computer Science — University of San Francisco – p. 5/??9-6: Step 2: filtering elements•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?Department of Computer Science — University of San Francisco9-7: Emitting HTML•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/??9-8: Emitting XML•We can also use XSLT to create new XML documents withdifferent 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/??9-9: Copying Nodes•When transforming from XML to XML, often, it’s useful to copysections 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, albumand title.Department of Computer Science — University of San Francisco9-10: Incorporating CSS•We can still use CSS to control presentational elements.•With HTML, we can just embed a ’link’ tag in the generatedHTML.Department of Computer Science — University of San Francisco – p. 10/??9-11: Incorporating CSS•If we’re emitting XML, we can instead embed a processinginstruction into the output document.•Note: this will work best if we do the XSLT on the server side.<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/??9-12: Referencing a stylesheet from an XML document•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 asingle pass and not apply the CSS. (firefox)Department of Computer Science — University of San Francisco9-13: Xpath•The examples we’ve seen so far match templates to elementsbased 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 on anelement’s position in the DOM tree.•XPath is a language for doing this.Department of Computer Science — University of San Francisco – p. 13/??9-14: XPath•In XPath, everything is dealt with as a path from the root of thetree.•To find a node, we’ll use a location path, which consists of aseries 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/??9-15: Axes•Axes consist of:•Children and parents, which have their usual meanings.•Ancestor, which means any node above the node of interest.•Descendant: any node below the node of interest.•Following: following siblings and their descendants.•Preceding: preceding siblings and their descendants.•SelfDepartment of Computer Science — University of San Francisco9-16: Node test•The second component of the location step is the node test.•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


View Full Document

USF CS 682 - Distributed Software Development

Documents in this Course
Load more
Download Distributed Software Development
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Distributed Software Development and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Distributed Software Development 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?