Subscribe: Advanced Topics in Web Development
Added By: Feedage Forager Feedage Grade C rated
Language: English
assignment  books  client side  client  courses books  courses  data  file  order  page  write programs  write  xml  xpath  xsl  xslt 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Advanced Topics in Web Development

UFCFX3-15-3: Advanced Topics in Web Development I

Module Blog, © BIT, UWE, 2015/16

Updated: 2018-03-06T08:54:45.444+00:00


.htacess file and xml reader example


Mapping the data to MySQL 2: Using XSLT

Another approach to mapping the dataset would be to use XSLT to write out the necessary SQL Schema and Insert statements. We could then feed this "rendering" to MySQL using a PHP built pipe.

XSLT (as a xml dom to other format converter) was created to get this kind of job done. Hence XSLT is a great tool for generating code.

"I'd rather write programs that write programs than write programs" said ap.

We will stick to using XSLT 1.0 & the oXygen editor. If you don't have access to OXygen then use a tool like Kernow.

(On the second semester sister module ATWD2 we will consider XSLT 2.0/3.0, XPATH 3.0 & XQuery in much more detail. For instance, using XSLT to generate PHP code.)

Re-exmine the source file: transport_v1.xml

It's always good to examine the source file/s (once again) before embarking on a XSL stylesheet.

We won't make any structural changes to our input file but notice the following:

  • the by 'car' percent value is derived. A sum of 'as driver' + 'as passenger';
  • hence the last seven percent values for any ward should add up to 100.

(Points worth recalling when we come to develop a Schema.)

The eXtensible Stylesheet Language

XSL is a family of (W3C) recommendations for defining XML document transformation and presentation (formatting).

XSL is really a pattern oriented transformation language. XPATH is used to find the patterns in one or more input documents. When the (user defined) patterns are matched, XSL applies the transformations associated with those patterns and writes out the result.

This makes XSLT (the implementation of XSL) like SQL & Prolog, a declartive programming language. Expressing the logic of the computation rather than the control flow. This is in contrast to imperative programming languages (like PHP) where one or more algorithms are implemented in terms of explicit steps.

To write XSL productively you need some XML aware tools. oXygen and Kernow are great because you can load a source document and try out various XPath expressions interactively. The other reason is that Namespaces play a crucial role when developing with the XML family of technologies. Tools that are namespace aware can help greatly.

Developing the Stylesheet

In the script that follows we've used XSLT 1.0 & XPATH 1.0.

Note how the script takes advantage of the well-ordered data in the input file (i.e. the mode elements are in the same order within each ward element). This order (position) is used to generate keys.

That is, the position of the (parent) ward element in relation to its siblings is worked out using the xpath expression: count(../preceding-sibling::*) + 1 (line 25).

(Question: why is this order not significant for the PHP script (xmltodb.php) and how might we go about not relying on the order in the XSLT code.)

Assignment FAQ & Corrections



A couple of things pointed out by students on the assignment spec:

  1. Part C) on book suggestions is missing a closing tag in the example data
  2. Part D) on borrowing data asks for the course id as a post parameter. This is not actually needed so can be omitted. (That said, if we wanted to track which students from which courses were using the books, it might be useful in some scenarios).


  1. what is the total percent (approximate) set aside for the optional sections of the assignment?
    It is difficult to give an exact answer on this, as marks will depend to some extent on the quality of the main components. That said, assignments implementing only the main components are unlikely to score 70% or above. So - very approximately, each optional section is worth up to 7.5%.
  2. What is the .htaccess file for?
    This file can contain Apache web server mod_rewrite directives to allow you to create clean (RESTful) URLs for your web service. For example if a user enters a URL like this can be converted to Frameworks such as Codeigniter will tend to have a preconfigured .htaccess file which may well do what you need already, though it's worth having a look at it to see what it is doing. Also see this post for a way to handle it with PHP
  3.   What is the physical submission for this assignment? 23rd Feb Correction: You will be required to hand in a single page sheet at the coursework hub, containing a link to your documentation file. Please see Blackboard Announcements for further details.
  4. Is there any reason why all of the book titles have a forward slash at the end of them? Should they be retained or can I get rid of them? These are not needed and are probably an artifact from the way the data was exported originally - you can get rid of them
  5. Are there any 'set' links we have to use for the client side, or do they just need to be entered into the report. No set links for the client page, but please make sure we have the link to your client URL in the documentation you provide at:
  6.  Does the client side need to have a XML and JSON version or just one?  You only need to use one of the data formats from your service on the client side - the choice is up to you.
  7. There are other courses in the books data apart from the "CC" ones. This is because the courses list only contains computing-related courses, but some books are common to other departments. Don't worry as we will test using only the course codes in the courses.xml
  8. What do we mean by " allows full browsing of the dataset "? By this we mean that you can view all the courses, then drill in to see all the books for that course, with the books list linked to a book detail page that also show the recommendations. You don't need a single page that shows all the books in one view.

Any other queries? Let us know via the comments.