Joseph Michael Bloggs Mr Joe
2 Gloucester Road Bristol Avon BS2 4QS
Repeating fields are fine in xml documents – remember that in relational dbs, it is normal practice to decompose them out to another table"> Joseph Michael Bloggs Mr Joe
2 Gloucester Road Bristol Avon BS2 4QS
Repeating fields are fine in xml documents – remember that in relational dbs, it is normal practice to decompose them out to another table">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.

Similar presentations


Presentation on theme: "UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT."— Presentation transcript:

1

2 UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT

3 Example (well-formed) XML document (xml lecture) <?xml version="1.0" encoding="UTF-8"?> <patient nhs-no="7503557856"> <name> <first>Joseph</first> <middle>Michael</middle> <last>Bloggs</last> <title>Mr</title> <previous /> <preferred>Joe</preferred> </name> <address> <street>2 Gloucester Road</street> <street /> <street /> <city>Bristol</city> <county>Avon</county> <postcode>BS2 4QS</postcode> </address> <tel> <home>0117 9541054</home> <mobile>07710 234674</mobile> </tel> <email>joe.bloggs@email.com</email> <fax /> </patient> Repeating fields are fine in xml documents – remember that in relational dbs, it is normal practice to decompose them out to another table

4 XSLT XSLT – Extensible Stylesheet Language Transformations is an application for specifying rules which transform one XML document into another document. It uses template rules in the stylesheet to match patterns in the input document and when a match is found it writes the template from the rule to the output tree. Basic XSLT processing model

5 XSLT Document Model (showing parser) xpath engine

6 XSLT Parser Processing Model Both the source document and XSLT stylesheet are loaded into the processor's memory. How this happens is dependent on the implementation. One option is that both are loaded as DOM documents under the control of a program. Another option is that the stylesheet is referenced by a processing instruction in the source XML document. IE7/8 or Netscape can load the stylesheet when the XML document is loaded.

7 XSLT Processing (again)

8 XSLT is a functional “4gl” programming language A function maps one set of “things” onto another set of “things” using one or more rules. simple function: x 2 = ysimple xslt “function” or “template” rule 12345---12345--- 1 4 9 16 25 - -‘ x y when this pattern found in the input document Reuben output this Hello Reuben Hello template

9 XSLT uses “XPath” to find nodes in a xml document Joseph Michael Bloggs Joe Example 1: ……………. do something with content xslt rule using xpath expression – match the element Example 2: : =./@nhs-no xslt rule using xpath expressions (2) – get the value of the attribute named “nhs-no” in the element.

10 o XPath is a language for addressing specific parts of an XML document. XPath, like the Document Object Model (DOM), models an XML document as a tree of nodes. o An XPath expression is a mechanism for navigating through and selecting nodes from the XML document. o An XPath expression is in a way analogous to a Structured Query Language (SQL) query used to select records from a database. o There are different types of nodes, including element nodes, attribute nodes and text nodes. XPath defines a way to compute a string-value for each type of node. o XPath defines a library of standard functions for working with strings, numbers and boolean expressions. XPath basics :

11 patient name title address fax tel first middle last previous preferred street1 street2 street3 city county postcode home mobile JosephMichaelBloggs Joe 2 Gloucester Rd BristolAvon BS2 4QS 01179541054 07710234674 Mr nhs-no 7503557856 KEY element content attribute the tree view of example xml document xpath is simply a way of finding specific nodes in a document tree – like files in a file hierarchy – e.g. “c:\teaching\myfiles\thisdoc.doc”.

12 xpath axes (node sets) xpath has thirteen axis child parent descendent ancestor descendent-of-self ancestor-of-self following-sibling preceding-sibling following preceding attribute namespace self

13 xslt & push and pull models of document processing push model - source document controls the structure – e.g cascading style sheet (CSS) – applies a style but cannot change the structure of the input document. pull model – the stylesheet controls the structure and the source documents acts as the data source. xslt can apply both the push and pull model - you can write a xslt stylesheet to change the order of elements, do calculations based on the number of elements (using xpath), do branching depending on an element value, generate other stylesheets, write java or c# code or source code for any other language, use svg to generate graphics, apply formatting object (fo) constructs that tell a fo-processor to lay out pages for printing or write pdf and almost everything else supported by other programming languages. hence it has all the constructs to apply our fundamental ‘Jackson’ concepts of sequence, selection and iteration.

14 Joseph Michael Bloggs Joe Mr 2 Gloucester Road Bristol Avon BS2 4QS 0117 9541054 07710 234674 joe.bloggs@email.com stylesheet “patient.xslt” used to generate HTML example xslt stylesheet “patient.xslt” (1)

15 example xslt stylesheet (2) minimum stylesheet: the xslt parser (msxml) that “built into” internet explorer applies the above stylesheet

16 xslt stylesheet fragment : from “patient.xslt” (3) fragment 1 Patient Record XSL Transformation Example Patient Record <table border="1" cellpadding="4" cellspacing="0" bordercolor="#cccccc" width="400"> NHS Number start the template end the template output a table output 1 row with two columns -write “NHS Number” in first column - write the value of the attrubute in the second column apply all other templates output: Patient Record XSL Transformation Example Patient Record <table border="1" cellpadding="4" cellspacing="0" bordercolor="#cccccc" width="400"> NHS Number 7503557856 [RESULT FROM APPLYING ALL OTHER TEMPLATES]

17 xslt stylesheet fragment : from “patient.xslt” (4) fragment 2 – make a selection Fax - test if the context node (“self”) is empty if it is write “-” otherwise output the content string of the context node; represented by “.” Email mailto: fragment 3– output a html hyperlink output joe.bloggs@email.com

18 example xslt stylesheet : from “patient.xslt” (5) fragment 4 – do a while loop (iteration) cycle through all the “street” nodes and if not empty then output any content full version of the “patient.xslt” file can be found with the other example files “patient.xml” now points to it ( notice how Internet Explorer applies the stylesheet )


Download ppt "UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT."

Similar presentations


Ads by Google