Assignment 6
Date : 12 Oct 2001
Due Date : Monday 22th Oct 2001
Look at the data in the file lab7data.xml
1) Create a DTD for the file
Write the following using XSLT (XPath is a subset of XSLT and can be used).
2) Print all book elements with one of the authors being "Tim O'Reilly"
3) Print the titles of all books published by "Tim O'Reilly"
4) Print the number of books published by O'Reilly
5) Print all books and articles (incollection) containing the word
"database" in the title subelement.
(hint: use the XPath function contains(string1, string2))
6) Print each element book/incollection in HTML format with the
following as separate lines:
title in bold,
names of authors in italics
booktitle and page (where applicable)
Publisher, year, isbn
Each book/incollection element should be an item of a
ordered (numbered) list (< ol > ...)
Submit your queries along with output.
NOTE 1: You can find an XSLT tutorial linked off the course home
page (and also here).
NOTE 2: To run XSLT queries, use lotusXSL as follows
- Include xalana.jar and xerces.jar in your system CLASSPATH. If you want to use extensions then include bsf.jar in your CLASSPATH.
- The class org.apache.xalan.xslt.Process provides a basic utility for
performing transformations. Use it as follows
java org.apache.xalan.xslt.Process -IN xmlsource -XSL stylesheet -OUT outputfile
Where xmlsource is the XML source file name, stylesheet is te XSL stylesheet file name and outputfile is the output file name.
Some of the options the command line utility can take (the flags are case insensitive):
- LF (Use linefeeds only on output -- default is CR/LF)
- CR (Use carriage returns only on output -- default is CR/LF)
- INDENT (Number of spaces to indent each level in output tree --default is 0)
- TT (Trace the templates as they are being called)
- TG (Trace each result tree generation event)
- TS (Trace each selection event)
- TTC (Trace the template children as they are being processed)
Use -IN to specify the XML source document.
-XSL to specify the XSL stylesheet file.
-TEXT if you want the output to include only element values (not element tags with element names and attributes).
- (Not required for the assignment). Another option is to write a program which uses the TraX interface to perform a transformation. Example: If you run SimpleTransform.java with birds.xml and birds.xslit will ouput birds.out.