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

XSLT and DTDs
a movie encyclopedia

Due: 2019.Dec.06 (Fri) in class

We will work with an XML-encoded database of information about movies, movies.xml (be sure to View Source). Here is a sample/starter movies.xsl (also View Source, to get the initial xml-declaration lines!). Submit your files on D2L, with the exact names “movies.xml”, “movies.xsl”, and (if opting for external-dtd) “movies.dtd”.

Part A

  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.

viewing the file: If you open your .xml file locally, either (a) use Firefox, or (b) in Chrome you need to provide the command-line switch, something like: /Applications/Google\ Chrome.app/contents/MacOS/Google\ Chrome --allow-file-access-from-files.

Tips:


Part B: DTD

  1. (17pts) Generate a DTD for the grammar (You can have the DTD either in-line in your xml file, or as an external file.) Validate the file, using the validator such as the one at xmlvalidation.com/.

    Your DTD must match the three provided movies. Use your best judgement about whether a field that occurs in all three is required, or optional, or allowed to have multiple entries.

    If you include the DTD in-line, enclose all your <!ELEMENT> and <!ATTLIST> information inside a single, enclosing <!DOCTYPE movies [ ]>: .

    <?xml  ?>
    <!DOCTYPE ancient_wonders [
      <!ELEMENT wonders (wonder*)>
      <!ELEMENT wonder >
      <!ATTLIST name
        lang >
      
    ]>
    

  2. (3pts) Define an entity4 &disney; which resolves to “Walt Disney Studios Motion Pictures” (or perhaps even as the image “”). (You can of course choose a different studio than Disney.)

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 the less-supported 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.)

The easiest solution is to compose two calls to translate: the first does most of the work, and then you pass the result to another call to translate which just handles " characters.

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

    <xsl:variable name="quot">"</xsl:variable>
    <xsl:variable name="apos">'</xsl:variable>
    <xsl:value-of select="concat('abc',$apos,'def',$quot,'ghi')"/>
         
h/t to a Michael Kay This is overkill compared to nesting calls to translate, but I mention it just if you'd been curious about whether/how XSLT allows variables.

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!

     
3 This 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.      
4 Okay okay, if you get technical, the “&” and “;” aren’t part of the entity. Still, you know what I mean. The ampersand and semicolon are part of how you denote an entity-literal. It's similar to how, in programming languages, quotes aren’t part of the string but just how you denote what the string-literal is.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.