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 – otch/ otch/ –See listings of Distillery xml with link to stylesheet Stylesheet with link to CSS CSS stylesheet
<!-- 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 --> Whiskies of Scotland Whiskys of Scotland Matches the top- level Document Elements written directly to the result Apply matching templates in the given element sequence – all children here
Match the element named Distillery Evaluate an expression and insert the result Here just the text in the current element
XSLT process XML document XSLT document XSLT process XML or plain text parameters 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
An XML case study A combination of a photo album and a family history dex.xqlhttp:// dex.xql
XML – a sample system eXist Native XML Database XQuery process Java Stores XML, XQuery,XSL CSS and binary files (JPEG) XSLT process CSS process Server Client Browser
Example – Family History Photo Image: jpeg Description: string Date: date Media: string Inscription: string Person Event Name: string Date : date age Place Address : string Lat: decimal Long: decimal BirthDeathMarriage
Many-many resolution in XML Photo Image: jpeg Description: string Date: date Media: string Inscription: string (Subject: ( Person: name Age: integer) | Animal : name )* Place: (address, lat, log) | name B/W photograph Family sitting round the fireplace Robin Wallace Kenneth Wallace 12 Francis Wallace Cat Miss Whitfield Claremont, Brows Lane, Formby
Example – Events Person Event Name: string Date : date Birth DeathMarriage child father mother Birth Francis Wallace Kenneth Wallace Ida Wallace New Brighton
xquery version "1.0"; (: List events for a person :) declare namespace request=" declare namespace 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 :=, (: order the events in ascending date order :) $elist := {for $e in $events order by $e/date return $e } return (: return the event list transformed by the stylesheet :) transform:transform($elist,$ss,$params) XQuery
XSLT Event List Evaluate an expression and insert the result
XSLT … : Born at Father, Mother : Child born at Mother XPath Filter conditions, implicitly anded
XSLT language Multilingual Output Imperative Control structures Procedural programming Template matching Functional XPath Functions Process Control Debugging
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 –
Result output Insert evaluated expression Insert plain text – …. Insert processing instruction – Insert a number – like a level number – Copy nodes into the output – Create a node –
Imperative Control Structures Imperative Control structures –Sequence of data and instructions –Selection One option – Multiple options – –Iteration Iterate over nodes in a sequence – Order nodes in the iteration –
Procedural programming Procedure call - –.. Call Parameters – Procedure definition –.. Procedure parameters –
Template matching Template definition – Template application – Recursive Apply most specific template to a node Declarative code a challenge to debug
Functional variables can be defined but they are constants –
XPath Functions Boolean Functions String functions Numeric Functions Node sequence functions
Modular Programming Inclusion of another stylesheet – Inclusion of tempates from a stylesheet –
Process control Stylesheet declaration – Output control – Serialisation – Key – Define attributes –
Debugging Output Debug message –
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’ – –Determine the basic structure of a data entry form – InfoPath
XML Schema in action QSEE XML Schema XML document Validator analysis Form Builder (InfoPath) Form Definition Form engine (InfoPath) XML Document Generalise (Trang) XML Document