Digital Media Technology

1 Digital Media TechnologyWeek 6: Introduction to XSLT Pe...
Author: Jessie Wells
0 downloads 2 Views

1 Digital Media TechnologyWeek 6: Introduction to XSLT Peter Verhaar

2 Example: XML source Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873 Haarlem 22 January 1873 Dear Sirs!

We beg to apply to you the kind request for sending us one week before the publication one copy of Bulwer's novel: Kenelm Chillingly, His adventures and opinions, which book you have in the press, for what we are inclined to pay 30 £. When it were possible to send us already now the first volume by the post; it would be yet more agreeable. Mr H.A. Kramers at Rotterdam readily will be our pledge.

your truly De Erven F. Bohn

3 Getting started Include a template that points to the root element of the XML source. Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873 ….

4 XML Result XSLT XML Source XML Result

5 Elements within Literal text can be added with the element. e.g. This sentence will be visible in the result. HTML tags may be added directly e.g. This text will be italicised

6 Elements within Use to select text from the XML source. e.g. Note that the paths in the select-attribute must depart from the element mentioned in the match-attribute of

7 XSLT stylesheet <xsl:text>XSLT transformation</xsl:text>

8 Exercise 1

9 Example: XML source Belgium Brussels Cyprus Nicosia Denmark Copenhagen

10 XSLT stylesheet

  • The capital of is .

11 needs to be used if all the elements on a certain level need to be shown.This XSLT element takes a select-attribute Note that the paths within must depart from the element that is mentioned mentioned in the select-attribute.

12 XSLT stylesheet

  • The capital of is .

13 Exercise 2

14 Use to sort a list alphabeticaly or numerically This XSLT element also takes a select-attribute. It refers to the element the XSLT processor must sort by must be the direct child of (or )

15 Exercise 3

16 takes a “test” attributeThe instructions within will only be carried out if the criterion in the test attribute can be evaluated as true Example:

17 Exercise 4

18 Operators that can be used to formulate such tests:The items that will be selected within the loop can be filtered by adding a criterion within square brackets, directly after the element name. Operators that can be used to formulate such tests: = Equal to != Not equal to < Less than > Greater than

19 Exercise 5

20 Elements within