xsl-list
[Top] [All Lists]

RE: Conditional extraction of data

2004-11-08 07:38:27
Actually, just for info and in case any of you like to do this sort of thing 
for fun, here are the exercises for this week.

Please do not post any answers (at least for a couple of weeks until we've all 
handed our assignments in, but preferably not at all).  I don't want to be 
failed for plagiarism and unfair collusion!  That's why I'll put the group in 
as a reference.

The module is an 8 week web applications module as part of an MSc studied via 
distance learning.  We first met XSLT last Tuesday afternoon (2nd November, 
2004).  The answers to the questions below (under my signoff) are to be in by 
midnight on Wednesday 10th Nov, 2004.

Cheers


Peter

Exercises for Seminar 4

The answers and/or discussion from the following exercises are to be submitted 
to the assignments folder by the end of day 7 of the seminar week.

Exercise 1

In the seminar, Listing 5 showed an improve JavaScript function for 
printElement() to traverse and list on the screen all elements of the DOM of 
the XML document in Listing 1.  Improve this JavaScript function by adding the 
functionality to also list on the screen the attributes and their values for 
each element.  Submit the entire XHTML document containing the complete 
JavaScript code to process the file orders.xml   (make sure you test it against 
the orders.xml file in the examples.zip file).

Exercise 2 (Difficult)

Create an XHTML document with the JavaScript code to open and build the DOM 
tree for orders.xml as in the seminar, but them also loads in and builds 
another DOM tree for another file... say orders2.xml as shown below

  <orders>
  <order>
~ <customerid limit="1500">65743</customerid> 
~ <status>pending</status> 
  <item instock="Y" itemid="HS05">
~ <name>Nike Horse Shoes</name> 
~ <price>120</price> 
~ <qty>4</qty> 
~ </item>
~ </order>
~ </orders>

Then build in the functionality to modify the DOM tree for the orders.xml by 
adding the order for customer ID 65734 from the above listing to the orders.xml 
DOM.  Then list the contents of the orders.xml DOM to the screen to verify 
this.  Please submit the XHTML file containing all the above JavaScript 
functionality.

  (HINT ... use the cloneNode() and appendChild() functions from the Node 
Functions table in the Seminar)


Exercise 3

The following are a series of exercises/ tasks which are all based on the 
data-file data.xml.  This file can be downloaded from 
http://student.kitcampus.com/projects/teacher2/wa/sem4/data.xml , and describes 
gravestones in a cemetery, the people commemorated on them, and the 
inscriptions. The root element is <cemetery> and under that are a series of 23 
<stone> elements. Within <stone> you find one or more <person> elements, some 
<inscrip> elements, and then probably <desc>, <photo> and <icon> elements.  A 
lot of the markup will be ignored for the purposes of these exercises.

Your set of tasks below involve writing XSL files to be used by the data.xml 
file to output XHTML script, and are as follows: 

1.      Produce a valid HTML document with a title, simply passing through all 
the text  The sample output for this task can be viewed at 
http://student.kitcampus.com/projects/teacher2/wa/sem4/ex1.html
2.      For each stone, make a new <h2> division titled `Stone ' plus the value 
of the `number' attribute
3.      Print the peoples' names in bold
4.      Put spaces between surname and forename
5.      Put each inscription in a block quote, and put a break at the end of 
every line; make the <i> produce italics
6.      Omit everything from the <person> except the contents of the <name>, 
and put each person in a separate paragraph
7.      Omit the <deco> and <photo> elements, and format the <died> element 
nicely after each person's name, with / between day and month, and month and 
year
8.      Improve the formatting or information display in whatever way interests 
you; can you, for instance, center the lines which have a with a `p' attribute 
with a value of `c'?
9.      Produce a table of contents for the catalogue as we left it in the 
final exercise of part 1; give each heading an identifier (the stone number 
will do, prefixed by "S"), and produce a list of numbers at the start, linked 
to the right stone.  The sample output for this task can be viewed at 
http://student.kitcampus.com/projects/teacher2/wa/sem4/ex9.html

Submit all 9 XSL scripts as answers to each of the above 9 tasks.