... Style sheet declaration (must be at the beginning of the file)‏">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.

Similar presentations


Presentation on theme: "CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT."— Presentation transcript:

1 CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT

2 XSLT EXtensible Stylesheet Language Transformations What is it? –w3c recommendation that applies style sheets to XML –Allows styles to be applied for outputting XML, to a web browser for instance. –Can also sort and filter data for output –Like CSS, separates formatting from content

3 Creating the XSLT (1/6)‏ ... Style sheet declaration (must be at the beginning of the file)‏

4 Creating the XSLT (2/6)‏ ... This is optional – purely demonstrates that parameters can be used in a similar way to variables.

5 Creating the XSLT (3/6)‏ ... Declares the output method. Can also output as “xml” and “text”.

6 Creating the XSLT (4/6)‏ ... Create a template that will be applied to any part of the XML that matches the expression. “/” is the expression for the root element.

7 Creating the XSLT (5/6)‏ ... value-of is used to extract the data from a XML element or a param. XHTML can be inserted where ever required…

8 Creating the XSLT (6/6)‏ ... Selects & applies a style for every element of a node-set as defined by the expression in the ‘select’ attribute.

9 Displaying XML using XSLT in PHP // Load the XML data source $xml= simplexml_load_file('grade.xml'); // one of these will work $xml= DOMDocument::loadXML(file_get_contents('grade.xml'); // Load the XML stylesheet $xsl = simplexml_load_file('grade.xsl'); // one of these will work $xsl = DOMDocument::loadXML(file_get_contents('grade.xsl'); // create an xslt processor instance $proc = new XSLTProcessor; // import the xsl stylesheet into the xslt processor $proc->importStyleSheet($xsl); // Transform and output the xml data source echo $proc->transformToXML($xml);

10 The output (unsorted)…

11 Sorting Data using the XSLT ......

12 The output (sorted)…

13 Summary XSLT allows style sheets to be applied to XML documents –Separates style from content –Can output as xml, html and text Use the reference on the next page. It is a good resource

14 Recommended Reading http://www.w3schools.com/xsl/default.asp - w3schools XSLT tutorial & reference


Download ppt "CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT."

Similar presentations


Ads by Google