RU beehive logo ITEC dept promo banner
ITEC 325
2016fall
ibarland

homelectshws
D2Lbreeze (snow day)

xslt
XSLT
a movie encyclopedia

Due: 2015.Apr.20 (Wed) 16:00 2016.Dec.02 (Fri) 11:00

We will work with an XML-encoded database of information about movies, movies.xml [be sure to View Source!]. (And, here is a sample/starter movies.xsl.) Submit your files on D2L, with the names “movies.xml” and “movies.xsl”.

  1. (3pts) Add one more movie to the file movies.xml.
  2. (15pts) Create an XSLT template which generates a page with a summary of each movie, looking similar to movies-goal.html.

  3. (2pts) Have your list sorted by release-year, in reverse order (most recent first).

    If you want, you can use nested xsl:sort tags to sort by year-month-day3. You should (re)arrange the movies in the source-file in such an order as to confirm that this sorting works.

Tips:


1 This is not as effective as a function like php's urlencode, but (a) XSLT 1.0 does not provide a good alternative, and (b) I'm not concerned with finding plugins to run XSLT 2.0. See specs §2.2 for a more technical list of (dis)allowed characters.      
2
The catch is that in XML, you can't have a string-literal (attribute) that contains BOTH an apostrophe AND a double-quote mark — so you can't pass a string to translate containing both those characters. Rats! (If you only need one of those two types of quotes, you can just delimit your string with the other type of quote, so it's not a problem.)

For XSLT 1.0, one solution is to use variables and concatenation, to create a string with both types of quotes in it:

           
    <xsl:variable name="apos">'</xsl:variable>
    <xsl:value-of select="concat('abc',$apos,'def',$quot,'ghi')"/>
         
h/t to a Michael Kay

But this digression is further than I want to go in this course — I want to focus on the ideas of XPATH, understanding the need for sanitizing, and reinforcing the notion of calling functions (in new languages). And if you were really using XSLT, hopefully you'd be finding support for XSLT 2.0, and you could just call its function encode-for-url, obviating the whole hack of translateing characters in the title anyway!

     
3This is actually following a standard CS trick: If you first sort by month and then by year, you'll get what you want as long as the sorting algorithm is “stable” — that is, it leaves tied elements in the same relative order they started in. It makes sense: after the first sort on months, all the Januaries come before all the Februaries. When you now sort by year, and two movies are tied for year, the January one will stay ahead of the February one, in a stable sort.      

homelectshws
D2Lbreeze (snow day)


©2016, Ian Barland, Radford University
Last modified 2016.Nov.28 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.