← Back to Archives

Shows page back up...

music

So, I've revitalized my Shows page which lists concerts and other musical engagements that I'm likely to be found at. It now has a feed. Technical details about the schema, xml and such below the fold.

[More:]

This was really just a simple proof of concept to answer the question, "Can I do semi-relational logic using just xml?". I did this in four parts:

  1. I defined a Relax NG (compact) schema, that's actually pretty simple: http://josephhall.org/shows/shows.rnc.

    It essentially defines a container venueShowList which contains two elements, venueList and showList which each contain multiple venue and show elements. Note: to preserve the relationality of the data model, you have to add a venueCodeContent code for each new venue that you add to the xml file. This code is a string like GAMH that will then be used to identify the venue and to associate a show with a venue.

  2. Then I coded up all the good upcoming shows and their venues into an xml file: http://josephhall.org/shows/shows.xml.

  3. Then, I had to write two xsl transforms (which takes the xml and transforms it into something else). The first transform, http://josephhall.org/shows/shows.xsl, was to take each show and put them in their own table rows in html. The second, http://josephhall.org/shows/shows-rss2.0.xsl, takes the shows and puts them into an rss 2.0 feed.

    The tricky parts of these transforms were 1) being able to match a venue code from a show and then pull in parts from the venue element and 2) sorting the shows in terms of their dates.

    For 1) the trick is to save the matched venueCode as a variable that you can then use in XPATH for matching:

    <xsl:template match="@venueCode"> <xsl:variable name="ven" select="."/> <xsl:value-of select="//sh:venue[@venueCode=$ven]/sh:url"/> </xsl:template>

    As for 2) the trick is to sort on parts of the xsd:date format in succession (here I do this using the XSL 2.0 functions *-from-date() but you could also just find the substring and use that using XSL 1.0 substring functions):

    <xsl:apply-templates select="sh:show"> <xsl:sort select="year-from-date(@date)"/> <xsl:sort select="month-from-date(@date)"/> <xsl:sort select="day-from-date(@date)"/> </xsl:apply-templates>

  4. Finally, I have a smarty template that pulls in the table row elements into the body of the shows.tpl file (which is called by shows.php). That was as easy as a simple {include file="show-list.tpl"} in the shows.tpl smarty template.