CSCI 5733.1
XML Application Development
Spring 2005
Final Examination

Name:  _________________________________

Time allowed: one hour and 20 minutes.  Total score: 30.

Open: lecture notes, every file I wrote and posted in my Web page and your project assignments.  No books or other materials are allowed.

Answer all questions.  Turn in both question and answer sheets (with the question sheets on top).  Plan your time well.

Academic honesty policy will be followed strictly.  Cheating will result in a failing grade of D or below and a permanent academic record. 

(1) [10 points] Consider the following xml document, bibalt.xml:

<bib>
   
    <book year="1994">
        <title>TCP/IP Illustrated</title>
        <author><last>Stevens</last><first>W.</first></author>
        <publisher>Addison-Wesley</publisher>
        <price>65.95</price>
    </book>

    <book year="1992">
        <title>Advanced Programming in the Unix environment</title>
        <author><last>Stevens</last><first>W.</first></author>
        <publisher>Addison-Wesley</publisher>
        <price>65.95</price>
    </book>

    <book year="2000">
        <title>Data on the Web</title>
        <author><last>Abiteboul</last><first>Serge</first></author>
        <author><last>Buneman</last><first>Peter</first></author>
        <author><last>Suciu</last><first>Dan</first></author>
        <publisher>Morgan Kaufmann Publishers</publisher>
        <price>39.95</price>
    </book>

    <book year="1999">
        <title>The Economics of Technology and Content for Digital TV</title>
        <editor>
            <last>Gerbarg</last><first>Darcy</first>
            <affiliation>CITI</affiliation>
        </editor>
            <publisher>Kluwer Academic Publishers</publisher>
        <price>129.95</price>
    </book>

     <book year="1992">
        <title>Advanced Programming in the Unix environment.  Volume 2</title>
        <author><last>Stevens</last><first>W.</first></author>
        <author><last>Suciu</last><first>Dan</first></author>
        <author><last>Buneman</last><first>Peter</first></author>
        <author><last>Gerbarg</last><first>Darcy</first></author>
       <publisher>Addison-Wesley</publisher>
        <price>75.95</price>
    </book>

</bib>

(a) Write a XQuery expression to return the number of books published per year (ordered by year) in the following format:

  <result>
    <numBooks year="1992" num="2"/>
    <numBooks year="1994" num="1"/>
    <numBooks year="1999" num="1"/>
    <numBooks year="2000" num="1"/>
  </result>

(b) Write a XQuery expression to return books with an author with the last name "Suciu" or "Stevens", but not both, in the following format.

  <result>
    <book year="1994">
        <title>TCP/IP Illustrated</title>
        <author><last>Stevens</last><first>W.</first></author>
        <publisher>Addison-Wesley</publisher>
        <price>65.95</price>
    </book>

    <book year="1992">
        <title>Advanced Programming in the Unix environment</title>
        <author><last>Stevens</last><first>W.</first></author>
        <publisher>Addison-Wesley</publisher>
        <price>65.95</price>
    </book>

    <book year="2000">
        <title>Data on the Web</title>
        <author><last>Abiteboul</last><first>Serge</first></author>
        <author><last>Buneman</last><first>Peter</first></author>
        <author><last>Suciu</last><first>Dan</first></author>
        <publisher>Morgan Kaufmann Publishers</publisher>
        <price>39.95</price>
    </book>
  </result>

(2) [6 points] Using bibalt.xml, give the XPath expressions for the following queries.

(a) All <author> elements who are co-authors of 'Peter Buneman'. The result should be:

<author><last>Abiteboul</last><first>Serge</first></author>
<author><last>Suciu</last><first>Dan</first></author>
<author><last>Stevens</last><first>W.</first></author>
<author><last>Suciu</last><first>Dan</first></author>
<author><last>Gerbarg</last><first>Darcy</first></author>

Noe that 'Peter Buneman' himself is not included in the result. It is not necessary to remove redundancy.

(b) Give the year attribute with the largest value, i.e. year="2000". You can assume all year values are in four digits.

(c) All <book> elements that are published before 1997.


(3) [10 points] Write a XSLT program to return the number of books published per year (order by year) in the following format:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<result>
<numBooks year="1992" num="2"/>
<numBooks year="1994" num="1"/>
<numBooks year="1999" num="1"/>
<numBooks year="2000" num="1"/>
</result>

A XSLT skeleton is provided for you so it is only necessary for you to define the template(s).

<?xml version='1.0'?>
<xsl:stylesheet version='1.0'
   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="xml" version="1.0" indent="yes" standalone="yes" />

<!-- Define your template(s) here. -->

</xsl:stylesheet>

(4) [4 points] True or false.

(a) WML variables are read-only and can only be written to once during initialization.

(b) The attribute ontimer for the <card> defines the action of a user-activated event.