|
Due:
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”.
Have your the review-link be a URL is (say) full-reviews.xml#Metropolis. This link does not need to lead to an actual, existing page; I just want you to demonstrate that you know how to add attributes to a tag.
For full credit, use translate to convert any spaces in the movie's title to become hyphens or +s, and change the following characters that don’t belong in URLs1 into safe characters (e.g. hyphens): < > = / ? % # & { } | \ ^ ~ [ ] ; / ? : @. You are not required to convert " characters as well, because it’s a mild pain, but feel free to2.
Hint: remember the count function.
hint: Recall the example of using position(), near the end of xpath-functions/. If you like, include the word “and” before the last item.
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:
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.
Enclose all your <!ELEMENT…> and <!ATTLIST…> information inside a single, enclosing <!DOCTYPE movies [ … ]>, similar to the lecture's DTD:
<?xml … ?>
<!DOCTYPE ancient_wonders [
<!ELEMENT wonders (wonder*)>
<!ELEMENT wonder …>
<!ATTLIST name
lang …>
⋮
]> |
Walt Disney Studios Motion Pictures(or perhaps even to the image ). You can of course choose a different studio than Disney.
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')…"/> |
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!
↩This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |