Sample Solutions for the XSLT Exercises of Lab 4 ================================================ These are possible ways to express the XSLT transformations Lab 4. There are also many equivalent solutions. ------------------------------------------------------------------------------------ 1. Return an element with a list of elements, containing in turn elements and , such that each country of the document appears once. Write the stylesheet so that iteration is achieved by recursive calls to templates. ------------------------------------------------------------------------------------ 2. Return a similar list, ordered by in descending order. Write the stylesheet so that iteration is expressed by elements. ------------------------------------------------------------------------------------ 3. Rewrite the preceding stylesheet in such a way that you use dynamic element constructors to construct the new elements. ------------------------------------------------------------------------------------ 4. Rewrite the stylesheet from Exercise 2 or 3 in such a way that you create country elements and name and population attributes and that you use shallow and deep copying wherever possible. ------------------------------------------------------------------------------------ 5. Return a list of elements, containing the name of the city, such that each city has an attribute population and another attribute country. The cities are returned according to their population, in descending order. Use iteration by template call. ------------------------------------------------------------------------------------ 6. Restructure the document by listing countries according to population, cities within each country according to population, and languages within each country according to percentage, all in descending order. ------------------------------------------------------------------------------------ 7. Return an element with a list of elements, alphabetically sorted, where each language from the countries documents occurs exactly once. Use the two approaches shown in the lecture. Version 1: XPath test for duplicates Version 2: Muenchian approach to duplicate elimination ------------------------------------------------------------------------------------ 8. Return an element with a list of elements, alphabetically sorted, where each language element containts a list of country elements, such that the language is spoken in the country, together with the number of speakers of the language in that country. Hint: You may need parameters, named templates, calls to templates, and the formating function format-number. Parameters and named templates are documented on the lecture slides. Note: XSLT 1.0 doesn't have decimal and integer types, it only has "number", which is double-precision floating point. To influence the output, we have to use the function format-number. ------------------------------------------------------------------------------------ 9. Create a stylesheet that produces an HTML layout of the countries document. Follow the example of the recipes layout from the lecture. Version 1: A table of countries with population and area Countries of the World
Country Population Area
Version 2: Countries separated by headings, plus full information Countries of the World

Countries of the World

Population:
Area: sq km

Cities of

City Population

Languages of

Language Percentage

%