Processing of structured documents, Session 5 (24.-25.2.)



  1. Study the sample documents: "http://www.univ.edu/students.xml" and "http://www.addresses.com/studAddr.xml". Construct the following queries using the XQuery language and give the results of the queries. You can create new elements as you wish.

    1. List the persons that are older than 20 years (now).

    2. For each student, list the name, the homecity, and the points of the project work.

    3. For each city, list the students that live in that city.


    You can train your XQuery skills by using some demo systems on the web:

    The sample data and queries of these systems come from the W3C XML Query Use Cases Working Draft.


  2. Assume that you have XML documents in the following format:

    <?xml version="1.0"?>
    
    <cities>
       <city name="Paris" country="France"/>
       <city name="Roma" country="Italia"/>
       <city name="Nice" country="France"/>
       <city name="Madrid" country="Espana"/>
       <city name="Milano" country="Italia"/>
       <city name="Firenze" country="Italia"/>
       <city name="Napoli" country="Italia"/>
       <city name="Lyon" country="France"/>
       <city name="Barcelona" country="Espana"/>
    </cities>
    
    

    ... but you would need to have the data grouped in the following way:

    <?xml version="1.0"?>
    <countries>
    <country name="France">
    <city>Paris</city>
    <city>Nice</city>
    <city>Lyon</city>
    </country>
    <country name="Italia">
    <city>Roma</city>
    <city>Milano</city>
    <city>Firenze</city>
    <city>Napoli</city>
    </country>
    <country name="Espana">
    <city>Madrid</city>
    <city>Barcelona</city>
    </country>
    </countries>
    
    

    Write an XSLT transformation that does the conversion. You should not assume that you know the set of countries or cities found in the document.

    Some tips:

    You can use a variable to store a set of elements or attributes. Below you see a format for a variable declaration, and below that a for-each clause that outputs, for each item in set 'x', an 'elem' element with an attribute 'attr' that gets as value the respective item of 'x'.

    
    <xsl:variable name="x" select="...expression" />
    
    <xsl:for-each select="$x">
      <elem attr="{.}">
      ...
      </elem>
    </xsl:for-each>
    
    

    If you have nested for-each clauses, like:

    <xsl:for-each select="$x">
       <xsl:for-each select="...">
       ...
       </xsl:for-each>
    </xsl:for-each>
    

    you can refer to the outer item in the select attribute of the inner for-each clause by a function call current() (instead of e.g. {.}). For instance, select="@country=current()".


  3. Project: Part 5

    Assume like in Part 4 that you have the prices (and maybe some general product information) in one file, and the purchase order information from Company B in another file.

    Final thoughts: What do you think: how much negotiation and preparation was needed between Company A and Company B before they could start doing business together? What may happen, if the products etc. change?

    Prepare a short report including the solutions for the Parts 1-5 in HTML. You should justify and comment your solutions/decisions, but no extensive general descriptions or implementation of the system (as a whole) are needed. The deadline is 14.3. at midnight (24:00). Submission instructions: fill out this form, where you can tell us the URL of your project page.


Helena Ahonen-Myka
Last modified: Tue Mar 4 16:24:27 EET 2003