XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round three / Summary and exercises / Exercises
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 3.)
Solutions are under Solutions to the exercises.
Exercise 1: Named templates
In an XML article, insert a formatted separator line at the end of each chapter using a named template as a subroutine.
Required file: aufgaben/kap03/a1-artikel.xml
Exercise 2: Variables and parameters
Extend the preceding solution to output “Ende von Kapitel 1”, and so on, at the end of a chapter. Since a named template already inserts the separator, it should do this too. Pass the current chapter to the named template through a parameter value.
Required file: aufgaben/kap03/a2-artikel.xml
Exercise 3: Runtime identifiers
Usegenerate-id()to prepend a table of contents with jump links to an XML article’s output.
Required file: aufgaben/kap03/a4-generate-id.xml
Exercise 4: Unparsed entities
Reuse a variation of the book-sales file to demonstrate further features. An XML file, graphics and the DTD are provided.
Figure: book file with illustrations.
The DTD declares book-cover graphics, buch1.gif through buch10.gif, as unparsed entities. Output them alongside the book information.
Required files: aufgaben/kap03/a5-buchdaten.xml, buch1.gif-buch10.gif
Exercise 5: Unparsed entities
Each book in the XML file has an element<verkauf>containing current sales figures. Represent the number as a bar chart using an HTML<img>with graphic rot.gif and an appropriately setwidthattribute.
Required files: as above, plus rot.gif
Figure: book file with bar chart.
Exercise 6: The function
document()
Add another document to the exercise 5 file containing summaries of the listed books. Insert these summaries next to their respective books. Include the external document usingdocument()and store it in a variable.
Required files: aufgaben/kap03/a6-buchdaten.xml, aufgaben/kap03/a6-buchdaten-inhalte.xml
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn