CSCI 5733
XML Application Development
Spring 2006
Homework #4

Due date: April 13th, 2006 (Thursday)

(1) (30%) AJAX. This assignment is based on the example, news.xml, in the AJAX lecture note. In news.xml, the news obtained by the news server, e.g., http://dcm.cl.uh.edu/yue/courses/xml/notes/general/news.pl?topic=China, is displayed in XML text as is. This is done by using responseText and is not too readable. Modify the program so that it uses responseXML and displays it in HTML style using a simple table. The output for selecting news from India should be displayed in a browser window as:

Output for questoin 1

(2) (20%) XPath question. Using the family tree examples in the XPath lecture notes, provide the XPath expressions for the following queries.

(a) A person who is a grandfather.

(b) A person with exactly two email addresses.

(c) The first <person> element appearing in the document.

(d) Without using the children attribute in the XPath, return all parent persons.

(3) (50%) XSLT question. Write a JSP program, h4.jsp, which uses two XSLT programs, h4html.xsl and h4xml.xsl, to transform news read from the news server http://dcm.cl.uh.edu/yue/courses/xml/notes/general/news.pl?topic=India and output either HTML or XML.

Your JSP program should accept two HTTP parameters:

format: the value can either be 'html' or 'xml'.
topic: countries you would like to retrieve news on, e.g., 'india', 'china', 'canada', etc.

Assume that the HTTP parameters are always correctly supplied.

As an example of the output requirements, suppose the news server returns the following snapshot: h4india.xml upon your program request.

If the format is HTML, the browser window receiving your program output using the URL:

http://dcm.cl.uh.edu:8080/youraccount/h4.jsp?format=html&topic=india

should display:

html output

Note that the news are sorted in ascending orders. Since the program is relatively easy, you need to strictly follow all display characteristics, including font (Verdana), background color of table header (#ffffcc) and alternative row colors (#ffffff and #ccffff).

If the format is XML:

http://dcm.cl.uh.edu:8080/youraccount/h4.jsp?format=xml&topic=india

Your program should return the following content:

<?xml version="1.0" encoding="UTF-8"?>
<news topic="india">
<site url="http://news.bbc.co.uk">
<headline>Bhopal gas victims march to Delhi </headline>
</site>
<site url="http://news.monstersandcritics.com">
<headline>India's roadmap for Kashmir </headline>
</site>
<site url="http://today.reuters.com">
<headline>JPMorgan to hire 4,000 in India, eyes China deal </headline>
<headline>UPDATE 1-JPMorgan to hire 4,000 in India, eyes China deal </headline>
</site>
<site url="http://www.bizjournals.com">
<headline>Convergys adding 2,000 employees in India </headline>
</site>
<site url="http://www.business-standard.com">
<headline>STMicroelectronics to invest $30 mn in India </headline>
<headline>Mutual funds sitting on Rs 17,656 cr </headline>
<headline>BSE m-cap accounts for 90 per cent of GDP </headline>
<headline>Infosys: Strategic move </headline>
<headline>Sensex breezes past 11,000 </headline>
<headline>Huge demand for business hotels in South India </headline>
<headline>RBI may not alter reverse repo rate </headline>
<headline>Dollar norms eased for investments </headline>
<headline>FM hardsells new tax scheme to corporates </headline>
<headline>Auto task force for special fund to finance global buys </headline>
<headline>Wal-Mart to shrink stores for India </headline>
<headline>Ranbaxy buys Glaxo Italy arm </headline>
<headline>Banks urged to beef up SLR reserve </headline>
<headline>NTPC won't buy gas from Shell </headline>
<headline>FMCG Feb sales growth at 5-year high of 10.6% </headline>
<headline>Payout-friendly firms' shares turn dearer </headline>
</site>
<site url="http://www.latimes.com">
<headline>Infosys to Set Up New Software Center </headline>
</site>
<site url="http://www.nzherald.co.nz">
<headline>Paran Balakrishnan: India gets mobile in numbers game </headline>
</site>
<site url="http://www.telegraphindia.com">
<headline>Maoists 'tax' Polish hikers </headline>
</site>
<site url="http://www.timesofoman.com">
<headline>Gujarati Wing's embroidery, drawing contest a big success </headline>
</site>
<site url="http://www.turkishdailynews.com.tr">
<headline>Changing India forces Bollywood to turn down volume </headline>
</site>
<site url="http://www.zeenews.com">
<headline>Time magazine commends Indian environmentalists </headline>
<headline>Some BJP leaders sabotaged Ram temple efforts: Uma </headline>
<headline>Infosys to invest Rs 1,250 cr in Andhra Pradesh </headline>
<headline>India, Pak work out road map to finalise accord on NTBs </headline>
</site>
</news>

Note that in the output, the <headline> news element are categorized under <site>. <site> are sorted in the ascending order of their urls.