Skip to content

Tasks

XPath

  1. 601-simple-expressions.txt 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>
a. Name of Institute:

<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 Formative Cycles are known:

id="NISA"
id="WAD"
id="MSN"

d. Years in which the title decrees of the Formative Cycles were published:

year="2009"
year="2010"
year="2008"

e.Intermediate Training Cycles (it is about obtaining the complete element):

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>

f. 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>

g. 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

h. 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
  1. 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>
a. Name of the modules taught at the 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

  1. 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>Higher</grade>
          <decreeTitle year="2009" />
        </cycle>
        <cycle id="DAW">
          <name>Web Applications 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>
    

    XSLT (1) - Exercise 1

    Without tags:

    <?xml version="1.0" encoding="UTF-8"?>
        Network Information Systems Administration    
        Web Application Development
        Sistemas Microinformáticos y Redes
    
    XSLT (1) - Exercise 2

    Párrafos:

    <?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>
    
    XSLT (1) - Exercise 3

    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>
    

  1. 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

  1. XML Transformation. XML to XML

    Given the following XML document, write XSLT stylesheets that return the desired response.

    <?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>
    
    Exercise 1. Convert tags to attributes:

    <?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:

    <?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>
    
    Exercise 3. Change the document structure:

    <?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>
    

  1. 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:

    <?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>
    
    Exercise 2. Convert some attributes to tags:

    <?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

  1. 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