Tasks¶
XPath¶
- XPath - Exercise 1 - Simple expressions
Given the following XML document, write the XPath expressions that return the desired response (shown in the boxes).
<?xml version="1.0" encoding="UTF-8"?>
<secondary-school>
<name>IES Abastos</name>
<web>http://www.iesabastos.org</web>
<cycles>
<cycle id="NISA">
<name>Network Information Systems Administration</name>
<grade>Higher</grade>
<decreeTitle year="2009" />
</cycle>
<cycle id="DAW">
<name>Web Application Development</name>
<grade>Higher</grade>
<decreeTitle year="2010" />
</cycle>
<cycle id="MSN">
<name>Microcomputer Systems and Networks</name>
<grade>Intermediate</grade>
<decreeTitle year="2008" />
</cycle>
</cycles>
</secondary-school>
<name>IES Abastos</name>
b. School website:
http://www.iesabastos.org
c. Name of Training Cycles:
Administration of Computer Network Systems
Web applications development
Microcomputer systems and networks
d. Acronyms by which the Training Cycles are known:
id="NISA"
id="WAD"
id="MSN"
e. Years in which the title decrees of the Training Cycles were published:
year="2009"
year="2010"
year="2008"
f. Intermediate Training Cycles (it is about obtaining the complete
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
<cycle id="MSN">
<name>Microcomputer Systems and Networks</name>
<grade>Medium</grade>
<decreeTitle year="2008"/>
</cycle>
g. Name of Higher Level Training Cycles:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
<name>Network Information Systems Administration</name>
<name>Web Application Development</name>
h. Name of Training Cycles prior to 2010:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Administration of Computer Network Systems
Microcomputer systems and networks
i. Name of the Formative Cycles of 2008 or 2010:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Web application development
Microcomputer systems and networks
- XPath - Exercise 2 - Simple expressions
Given the following XML document, write the XPath expressions that return the desired response (shown in the boxes).
<?xml version="1.0" encoding="UTF-8"?>
<school>
<modules>
<module id="0228">
<name>Web Applications</name>
<course>2</course>
<weeklyHours>4</weeklyHours>
<cycle>MSN</cycle>
</module>
<module id="0372">
<name>Database Management</name>
<course>1</course>
<hoursWeekly>5</hoursWeekly>
<cycle>NISA</cycle>
</module>
<module id="0373">
<name>Markup languages and information management systems</name>
<course>1</course>
<hoursWeekly>3</hoursWeekly>
<cycle>NISA</cycle>
<cycle>WAD</cycle>
</module>
<module id="0376">
<name>Web Application Deployment</name>
<course>2</course>
<hoursWeekly>5</hoursWeekly>
<cycle>WAD</cycle>
</module>
</modules>
</school>
Web Applications
Database management
Markup languages and information management systems
Implementation of web applications
b. Name of the NISA cycle modules:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Database management
Markup languages and information management systems
Implementation of web applications
c. Name of the modules taught in the second year of any cycle:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Web applications
Implementation of web applications
d. Name of the modules of less than 5 hours per week:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Web applications
Markup languages and information management systems
e. Name of the modules taught in the first NISA course:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
Database management
Markup languages and information management systems
f. Weekly hours of modules of more than 3 hours per week:
Note: Solve this exercise in two different ways, in a single search step and in two search steps.
4
5
5
XSL¶
-
XSLT Transformations
Given the following XML document, write the XPath expressions that return the desired response (shown in the boxes).
<?xml version="1.0" encoding="UTF-8"?> <secondary-school> <name>IES Abastos</name> <web>http://www.iesabastos.org</web> <cycles> <cycle id="NISA"> <name>Network Information Systems Administration</name> <grade>Upper</grade> <decreeTitle year="2009" /> </cycle> <cycle id="DAW"> <name>Web Applications Development</name> <grade>Upper</grade> <decreeTitle year="2010" /> </cycle> <cycle id="MSN"> <name>Microcomputer Systems and Networks</name> <grade>Intermediate</grade> <decreeTitle year="2008" /> </cycle> </cycles> </secondary-school>
XSLT (1) - Exercise 1
Without tags:
XSLT (1) - Exercise 2<?xml version="1.0" encoding="UTF-8"?> Network Information Systems Administration Web Application Development Sistemas Microinformáticos y Redes
Párrafos:
XSLT (1) - Exercise 3<?xml version="1.0" encoding="UTF-8"?> <html> <p>Network Information Systems Administration</p> <p>Web Application Development</p> <p>Microcomputer Systems and Networks</p> </html>
List:
<?xml version="1.0" encoding="UTF-8"?> <html> <ul> <li>Network Information Systems Administration</li> <li>Web Application Development</li> <li>Microcomputer Systems and Networks</li> </ul> </html>
XSLT (1) - Exercise 4
Table:
<?xml version="1.0" encoding="UTF-8"?> <html> <table border="1"> <tr> <td>Network Information Systems Administration</td> </tr> <tr> <td>Web Application Development</td> </tr> <tr> <td>Microcomputer Systems and Networks</td> </tr> </table> </html>
-
XSLT Transformation. XML to HTML
Given the following xml document
<?xml version="1.0" encoding="UTF-8"?> <secondary-school> <name>IES Abastos</name> <web>http://www.iesabastos.org</web> <cycles> <cycle id="NISA"> <name>Computer Network Systems Management</name> <grade>Higher</grade> <decreeTitle year="2009" /> </cycle> <cycle id="DAW"> <name>Development of Web Applications</name> <grade>Higher</grade> <decreeTitle year="2010" /> </cycle> <cycle id="MSN"> <name>Microcomputer Systems and Networks</name> <grade>Intermediate</grade> <decreeTitle year="2008" /> </cycle> </cycles> </secondary-school>
Exercise 1. Paragraphs
<?xml version="1.0" encoding="UTF-8"?> <html> <h1>IES Abastos</h1> <p>Computer Network Systems Management</p> <p>Development of Web Applications</p> <p>Microcomputer Systems and Networks</p> </html>
Exercise 2. List:
<?xml version="1.0" encoding="UTF-8"?> <html> <h1>IES Abastos</h1> <p>Web page: <a href="http://www.iesabastos.org/"> http://www.iesabastos.org/</a></p> <ul> <li>Computer Network Systems Management</li> <li>Development of Web Applications</li> <li>Microcomputer Systems and Networks</li> </ul> </html>
Exercise 3. Table:
<?xml version="1.0" encoding="UTF-8"?> <html> <h1>IES Abastos</h1> <p>Web page: <a href="http://www.iesabastos.org/"> http://www.iesabastos.org/</a></p> <table border="1"> <tr> <th>Cycle name</th> <th>Grade</th> <th>Year of title</th> </tr> <tr> <td>Computer Network Systems Management</td> <td>High</td> <td>2009</td> </tr> <tr> <td>Development of Web Applications</td> <td>High</td> <td>2010</td> </tr> <tr> <td>Microcomputer Systems and Networks</td> <td>Intermediate</td> <td>2008</td> </tr> </table> </html>
XML to XML¶
-
XML Transformation. XML to XML
Given the following XML document, write XSLT stylesheets that return the desired response.
Exercise 1. Convert tags to attributes:<?xml version="1.0" encoding="UTF-8"?> <museums> <museum> <name>Prado Museum</name> <city>Madrid</city> <country>Spain</country> </museum> <museum> <name>British Museum</name> <city>London</city> <country>United Kingdom</country> </museum> <museum> <name>National Gallery</name> <city>London</city> <country>United Kingdom</country> </museum> </museums>
<?xml version="1.0" encoding="UTF-8"?> <museums> <museum name="Museo del Prado" city="Madrid" country="Spain"/> <museum name="British Museum" city="London" country="United Kingdom"/> <museum name="National Gallery" city="London" country="United Kingdom"/> </museums>
Exercise 2. Convert some tags to attributes:
Exercise 3. Change the document structure:<?xml version="1.0" encoding="UTF-8"?> <museums> <museum> <name>Prado Museum</name> <location city="Madrid" country="Spain"/> </museum> <museum> <name>British Museum</name> <location city="London" country="United Kingdom"/> </museum> <museum> <name>National Gallery</name> <location city="London" country="United Kingdom"/> </museum> </museums>
<?xml version="1.0" encoding="UTF-8"?> <cities> <city> <name>Madrid</name> <country>Spain</country> <museum>Prado Museum</museum> </city> <city> <name>London</name> <country>United Kingdom</country> <museum>British Museum</museum> </city> <city> <name>London</name> <country>United Kingdom</country> <museum>National Gallery</museum> </city> </cities>
Exercise 4. Change the structure of the document and some elements in attributes:
<?xml version="1.0" encoding="UTF-8"?> <cities> <city name="Madrid" country="Spain"> <museum>Prado Museum</museum> </city> <city name="London" country="United Kingdom"> <museum>British Museum</museum> </city> <city name="London" country="United Kingdom"> <museum>National Gallery</museum> </city> </cities>
Exercise 5. Change the structure of the document and some labels in attributes:
<?xml version="1.0" encoding="UTF-8"?> <countries> <country name="Spain"> <museum museum="Museo del Prado" city="Madrid"/> </country> <country name="United Kingdom"> <museum museum="British Museum" city="London"/> </country> <country name="United Kingdom"> <museum museum="National Gallery" city="London"/> </country> </countries>
-
XML Transformations. XML to XML
Given the following XML document, write XSLT style sheets that return the desired response.
<?xml version="1.0" encoding="UTF-8"?> <museums> <museum name="Museo del Prado" city="Madrid" country="Spain"/> <museum name="British Museum" city="London" country="United Kingdom"/> <museum name="National Gallery" city="London" country="United Kingdom"/> </museums>
Exercise 1. Convert attributes to tags:
Exercise 2. Convert some attributes to tags:<?xml version="1.0" encoding="UTF-8"?> <museums> <museum> <name>Prado Museum</name> <city>Madrid</city> <country>Spain</country> </museum> <museum> <name>British Museum</name> <city>London</city> <country>United Kingdom</country> </museum> <museum> <name>National Gallery</name> <city>London</city> <country>United Kingdom</country> </museum> </museums>
<?xml version="1.0" encoding="UTF-8"?> <museums> <museum location="Madrid (Spain)">Prado Museum</museum> <museum location="London (United Kingdom)">British Museum</museum> <museum location="London (United Kingdom)">National Gallery</museum> </museums>
Exercise 3. Change the document structure and convert some attributes to tags:
<?xml version="1.0" encoding="UTF-8"?> <cities> <city name="Madrid"> <country>Spain</country> <museum>Prado Museum</museum> </city> <city name="London"> <country>United Kingdom</country> <museum>British Museum</museum> </city> <city name="London"> <country>United Kingdom</country> <museum>National Gallery</museum> </city> </cities>
Exercise 4. Change structure:
<?xml version="1.0" encoding="UTF-8"?> <countries> <country name="Spain"> <city name="Madrid"> <museum name="Prado Museum"/> </city> </country> <country name="United Kingdom"> <city name="London"> <museum name="British Museum"/> </city> </country> <country name="United Kingdom"> <city name="London"> <museum name="National Gallery"/> </city> </country> </countries>
Exercise 5. Change the document structure:
<?xml version="1.0" encoding="UTF-8"?> <places> <place type="museum"> <location name="city">Madrid</location> <location name="country">Spain</location> <name>Prado Museum</name> </place> <place type="museum"> <location name="city">London</location> <location name="country">United Kingdom</location> <name>British Museum</name> </place> <place type="museum"> <location name="city">London</location> <location name="country">United Kingdom</location> <name>National Gallery</name> </place> </places>
XML to text¶
-
The goal of this task is to learn how to transform an XML document into a text document.
A school have an XML document which contains the marks of different modules.
<?xml version = "1.0" encoding = "UTF-8"?> <department name="Computing"> <students> <student> <name>Frederick</name> <lastname>Garcia</lastname> <lastname>Puig</lastname> <credits> <credit> <name>Markup languages</name> <mark>6</mark> </credit> <credit> <name>Programming</name> <mark>5</mark> </credit> <credit> <name>Database</name> <mark>3</mark> </credit> </credits> </student> <student> <name>Filomenu</name> <lastname>Pi</lastname> <lastname>Bru</lastname> <credits> <credit> <name>Markup languages</name> <mark>10</mark> </credit> <credit> <name>Programming</name> <mark>9</mark> </credit> <credit> <name>Database</name> <mark>10</mark> </credit> </credits> </student> <student> <name>Manolito</name> <lastname>Puigdevall</lastname> <lastname>Torres</lastname> <credits> <credit> <name>Markup languages</name> <mark>2</mark> </credit> <credit> <name>Programming</name> <mark>3</mark> </credit> <credit> <name>Database</name> <mark>9</mark> </credit> </credits> </student> <student> <name>Bernat</name> <lastname>Joy</lastname> <credits> <credit> <name>Markup languages</name> <mark>5</mark> </credit> <credit> <name>Programming</name> <mark>1</mark> </credit> <credit> <name>Database</name> <mark>6</mark> </credit> </credits> </student> <student> <name>Filibert</name> <lastname>Blanch</lastname> <lastname>Blanch</lastname> <credits> <credit> <name>Markup languages</name> <mark>7</mark> </credit> <credit> <name>Programming</name> <mark>4</mark> </credit> <credit> <name>Database</name> <mark>4</mark> </credit> </credits> </student> <student> <name>Magdalena</name> <lastname>Roig</lastname> <lastname>Fernández</lastname> <credits> <credit> <name>Markup languages</name> <mark>5</mark> </credit> <credit> <name>Programming</name> <mark>5</mark> </credit> <credit> <name>Database</name> <mark>5</mark> </credit> </credits> </student> </students> </department>
They need a list of marks from the Markup Language module that looks like this:
Marks from // Markup Languages // -------------------------------- Federico Garcia: 6 Filomenu Pi: 10 Manolito Puigdevall: 2 Bernat Alegria: 5 Filibert Blanch: 7 Magdalena Roig: 5
XML storage¶
-
BaseX for dummies
Do the exercises contained in the step by step guide of BaseX for dummies document. You can download the XML document factbook.xml.
Create an screenshot for each exercise and save them in Aules.
-
Given the following XML document bookstore.xml:
- Create new XML database called
Bookstore
. - Do the following tasks (save every query in a document,
531-##.xq
):- List the title of all the books.
- List year and title of all books, ordered by year.
- List the books whose price is 19.95
- List books published before the year 2000
- List year and title of books published in English after 2004.
- Show the names of the authors that appear in the document, without repetitions, in alphabetical order.
- For each book, list its title and authors grouped in a
<result>
element. - For each book, get its title and the number of authors, grouped in a
<book>
element. - Generate an HTML document with a header that says "Book List" followed by a 3-column table showing the title, author and price of each book. The table should have borders and the first row should be specially formatted with column names. The title and editorial columns will be aligned to the left, and the price to the right.
- Generate an HTML document with the information of the books on web category. The total price value is a field calculated using a query with a let clause.
- Add the following document bookstore_2.xml to Bookstore database.
- Create new XML database called
-
Do the exercises you will find in the following link: https://ioc.xtec.cat/materials/FP/Recursos/fp_asx_m04_/web/fp_asx_m04_htmlindex/WebContent/u3/a3/activitats.html
-
Repeat exercises 2.9 and 2.10 from task 531 using Javascript and the DOM API.