USF CS 682 - Distributed Software Development

Unformatted text preview:

{small lecturenumber - heblocknumber :} XSLTaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Outputaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Our CD databaseaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Step 1: Using XSLT to emit plain textaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Step 2: filtering elementsaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Emitting HTMLaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Emitting XMLaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Copying Nodesaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Incorporating CSSaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Incorporating CSSaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Referencing a stylesheet from an XML documentaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Xpathaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} XPathaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Axesaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Node testaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Shortcutsaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Examplesaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Predicatesaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Examplesaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} So what's all this good for?addtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Sortingaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Parameters in XSLTaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Modifying XML with the DOMaddtocounter {blocknumber}{1}Distributed Software DevelopmentXSLTChris BrooksDepartment of Computer ScienceUniversity of San FranciscoDepartment of Computer Science — University of San Francisco – p.1/??7-0: XSLTXSLT is an XML-based language that allows you todeclaratively specify how a document should be changedor transformed.You specify the output for a particular element; no needto manage tree traversal.Useful for:Emitting an HTML display of an XML documentConverting between tag vocabulariesExtracting plain text from an XML documentAUtomatically modifying or filtering an XML document.Department of Computer Science — University of San Francisco – p.2/??7-1: OutputYou can transform an XML document into:Plain textHTMLXML (or any flavor thereof)Department of Computer Science — University of San Francisco – p.3/??7-2: 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/??7-3: Step 1: Using XSLT to emit plaintextTo 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 nexusMost modern browsers have XSLT supportDebugging is easier from the command lineDepartment of Computer Science — University of San Francisco – p.5/??7-4: Step 2: filtering elementsThat’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 Francisco – p.6/??7-5: Emitting HTMLWe 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 XMLWe 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-7: Copying NodesWhen transforming from XML to XML, often, it’s useful tocopy 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 orattributes.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/??7-8: Incorporating CSSWe 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 CSSIf 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 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-10: Referencing a stylesheet froman XML documentThe command line is great for debugging, but much of thetime, 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 makea single pass and not apply the CSS. (firefox)Department of Computer Science — University of San Francisco – p.12/??7-11: XpathThe 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 elementMatch all text nodesMatch all children of an author nodeEssentially, 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: XPathIn 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 ofa series of location steps.A location step consists of:An axis that tells us which direction to travelA node test that specifies which types of nodes applypredicates that use boolean tests to help filter nodes.Department of Computer Science — University of San Francisco – p.14/??7-13: AxesAxes consist


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?