Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)

Similar presentations


Presentation on theme: "XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)"— Presentation transcript:

1 XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)

2 Overview Introduction to Stylesheets Using XSLT to create HTML Using XSLT to do XML to XML conversion Using XSLT to sort and count

3 Stylesheets A stylesheet is a file which contains a declarative set of rules for converting an XML document into another document, which can be XML, HTML, plain text …

4 XSLT Transformations XSLT style sheet: template rules –pattern which specifies which tree it applies to –pattern which specifies which tree it should output XSLT processor –reads XML document and XSLT stylesheet –carries out the instructions in the stylesheet –outputs a new document

5 Stylesheet top-level elements …

6 Template Matching XPath is a language for addressing parts of an XML document, and is used by XSLT in the match attribute of a template e.g. matches any sentence element. The stylesheet processor goes through the XML document one element at a time, finds the first template which that element matches, and carries out the instructions in that template.

7 Template Matching (cont) If the element does not match any template in the stylesheet, then the default behaviour is for the processing to pass through to the children of this element without carrying ot any instructions. When the processing reaches an element which has only text children, the result of processing these children is to print out the text.

8 Some examples of patterns * matches any element / matches the top-level element sentence/word matches any word element with a sentence parent word[@pos=‘noun’] matches any noun element whose pos attribute has the value noun Many many other possibilities …

9 Using XSLT to create HTML Write a stylesheet which creates an HTML document Load the document into a browser (Some browsers will do the XSL processing internally e.g. IE5 but many others don’t yet allow this …)

10 displaysentence.xsl Paragraph

11 removemarkup.xsl

12 Treatment of whitespace You can specify what should happen to the whitespace in a document using the and elements. Each of these takes an element attribute which contains a list of element names. If you want to see how this works, try putting or below the declaration.

13 Sorting XSLT can be used to sort elements by alphabetical or numerical order, according to attribute values, text contents, in ascending or descending order, and more …

14 sortwords.xsl

15 Counting XSLT can also be used to count or number elements

16 countwords.xsl


Download ppt "XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)"

Similar presentations


Ads by Google