1 / 26

XSLT XML DBs , and Schemas

XSLT XML DBs , and Schemas. Week 18 DSA. The Whisky Case study. XSLT can be applied in the client. Add a xml processing instruction to the xml to bind to a XSLT script http://www.cems.uwe.ac.uk/~cjwallac/apps/scotch/ See listings of Distillery xml with link to stylesheet

Download Presentation

XSLT XML DBs , and Schemas

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XSLTXML DBs ,and Schemas Week 18 DSA

  2. The Whisky Case study • XSLT can be applied in the client. • Add a xml processing instruction to the xml to bind to a XSLT script • http://www.cems.uwe.ac.uk/~cjwallac/apps/scotch/ • See listings of • Distillery xml with link to stylesheet • Stylesheet with link to CSS • CSS stylesheet

  3. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- This stylesheet selects some elements from the whisky XML data, formats for display using classes. Only some tags are included - the remaining data is ignored. Connection with the css stylesheet is via class tags. Note these classes should be documented --> <!-- This Template matches the root of the document --> <xsl:template match="/"> <html> <head> <title>Whiskies of Scotland</title> <link rel="stylesheet" type="text/css" href="whisky_xsl.css"/> </head> <body> <h1>Whiskys of Scotland</h1> <xsl:apply-templates/> </body> </html> </xsl:template> Matches the top-level Document Elements written directly to the result Apply matching templates in the given element sequence – all children here

  4. <!-- This matches (any) Distillery tag in the document.--> <xsl:template match="Distillery"> <div class="main"> <xsl:apply-templates/> </div> </xsl:template> <!-- This matches (any) Name tag in the document.--> <xsl:template match="Name"> <h2><xsl:value-of select='.'/></h2> </xsl:template> <xsl:template match="Address"> <div class="em"><xsl:value-of select='.'/></div> </xsl:template> Match the element named Distillery Evaluate an expression and insert the result Here just the text in the current element

  5. XSLT process parameters XML document XML or plain text XSLT process XSLT document Parse inputs, set context to root; While nodes in context, for each node, check if any templates match – choose the most specific and apply the template Apply this recursively

  6. An XML case study • A combination of a photo album and a family history • http://www.cems.uwe.ac.uk/chriswallace/index.xql

  7. XML – a sample system Browser CSS process Client Server XSLT process Stores XML, XQuery,XSLCSS and binary files (JPEG) XQuery process Native XML Database eXist Java

  8. Example – Family History Person Photo age Name: string Image: jpeg Description: string Date: date Media: string Inscription: string Event Date : date Place Birth Death Marriage Address : string Lat: decimal Long: decimal

  9. Many-many resolution in XML <photo id="2"> <medium>B/W photograph</medium> <description>Family sitting round the fireplace</description> <subject> <person>Robin Wallace</person> </subject> <subject> <person>Kenneth Wallace</person> </subject> <subject> <age>12</age> <person>Francis Wallace</person> </subject> <subject> <animal>Cat</animal> </subject> <subject> <person>Miss Whitfield</person> </subject> <place> <address>Claremont, Brows Lane, Formby</address> <long>-3.06608</long> <lat>53.55555</lat> </place> </photo> Photo Image: jpeg Description: string Date: date Media: string Inscription: string (Subject: ( Person: name Age: integer) | Animal : name )* Place: (address, lat, log) | name

  10. Example – Events child Person Birth father Name: string mother <event> <class>Birth</class> <person>Francis Wallace</person> <date>1911-04-26</date> <father> <person>Kenneth Wallace</person> </father> <mother> <person>Ida Wallace</person> </mother> <place>New Brighton</place> </event> Event Date : date Death Marriage

  11. xquery version "1.0"; (: List events for a person :) declare namespace request="http://exist-db.org/xquery/request"; declare namespace transform = "http://exist-db.org/xquery/transform"; let $person := request:request-parameter('person',''), (: get the set of events in which this person is involved :) $events := document(/'db/history/events.xml')/eventList/event[.//person = $person], (: get the stylesheet :) $ss := document('/db/history/eventList.xsl'), (: set the 'focus' of the event list to the person :) $params := <parameters> <param name="focus" value="{$person}"/> </parameters>, (: order the events in ascending date order :) $elist := <eventList> {for $e in $events order by $e/date return $e } </eventList> return (: return the event list transformed by the stylesheet :) transform:transform($elist,$ss,$params) XQuery

  12. XSLT <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="focus"/> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <link rel="stylesheet" href="photos.css" type="text/css"/> <title>Event List</title> </head> <body> <h2> <xsl:value-of select="$focus"/> </h2> <xsl:apply-templates/> </body> </html> </xsl:template> Evaluate an expression and insert the result

  13. XSLT … <xsl:template match="eventList"> <xsl:apply-templates/> <hr/> </xsl:template> <xsl:template match="event[class='Birth'][person = $focus]"> <h3> <xsl:value-of select="date"/> : Born at <xsl:value-of select="place"/> </h3> <p>Father <xsl:value-of select="father/person"/>, Mother <xsl:value-of select="mother/person"/> </p> </xsl:template> <xsl:template match="event[class='Birth'][father/person = $focus]"> <h3> <xsl:value-of select="date"/> : Child <xsl:value-of select="person"/> born at <xsl:value-of select="place"/> </h3> <p> Mother <xsl:value-of select="mother/person"/> </p> </xsl:template> XPath Filter conditions, implicitly anded

  14. XSLT language • Multilingual • Output • Imperative Control structures • Procedural programming • Template matching • Functional • XPath Functions • Process Control • Debugging

  15. Multi-lingual • Plain text and plain xml • xsl (identified by the xsl:namespace) • XPath to define node-sets • Filter conditions to select subsets • XPath functions to manipulate the nodes • Comments • <xsl:comment>

  16. Result output • Insert evaluated expression • <xsl:value-of select=“exp”/> • Insert plain text • <xsl:text>…. </xsl> • Insert processing instruction • <xsl:processing-instruction> • Insert a number – like a level number • <xsl:number> • Copy nodes into the output • <xsl:copy-of> • <xsl:copy> • Create a node • <xsl:element> • <xsl:attribute>

  17. Imperative Control Structures • Imperative Control structures • Sequence of data and instructions • Selection • One option • <xsl:if > • Multiple options • <xsl:choose> • <xsl:when> • <xsl:otherwise> • Iteration • Iterate over nodes in a sequence • <xsl:for-each> • Order nodes in the iteration • <xsl:sort>

  18. Procedural programming • Procedure call - • <xsl:call-template name=“proc”>.. • Call Parameters • <xsl:with-param name=“x” select=“30”> • Procedure definition • <xsl:template name=“proc”>.. • Procedure parameters • <xsl:param name=“x”>

  19. Template matching • Template definition • <xsl:templates match=“path”> • Template application • <xsl:apply-templates select=“nodeset”> • Recursive • Apply most specific template to a node • Declarative code a challenge to debug

  20. Functional • variables can be defined but they are constants • <xsl:variable name=“a” value=“exp”/> • <xsl:value-of select=“$a”/>

  21. XPath Functions • Boolean Functions • String functions • Numeric Functions • Node sequence functions

  22. Modular Programming • Inclusion of another stylesheet • <xsl:include> • Inclusion of tempates from a stylesheet • <xsl:import>

  23. Process control • Stylesheet declaration • <stylesheet> • Output control • <xsl:output method=“text”/> • Serialisation • <xsl:preserve-space> • <xsl:strip-space> • Key • <xsl:key> • Define attributes • <xsl:attribute-set>

  24. Debugging • Output Debug message • <xsl:message>

  25. XML Schema • A definition of the structure of a class of XML documents. • Uses • Check that a given document is a member of the class – ‘Validation’ • http://tools.decisionsoft.com/schemaValidate/ • Determine the basic structure of a data entry form – InfoPath

  26. XML Schema in action QSEE Generalise (Trang) XML document XML Schema XML Document Validator Form Builder (InfoPath) Form Definition analysis Form engine (InfoPath) XML Document

More Related