I am working on a webpage that publishes a schedule of presentations based on an XML feed that I don't have access to change.
The feed looks like this:
<track name="Track 1">
<session name="Session 1" starttime="2012-06-06 10:45" endtime="2012-06-06 12:45">
<presentation name="Presentation 1">
...presentation info
</presentation>
<presentation name="Presentation 2">
...presentation info
</presentation>
</session>
<session name="Session 2" starttime="2012-06-06 10:45" endtime="2012-06-06 12:45">
<presentation name="Presentation 3">
...presentation info
</presentation>
<presentation name="Presentation 4">
...presentation info
</presentation>
</session>
<session name="Session 3" starttime="2012-06-07 08:45" endtime="2012-06-07 10:45">
<presentation name="Presentation 5">
...presentation info
</presentation>
<presentation name="Presentation 6">
...presentation info
</presentation>
</session>
</track>
At present, I am doing an <xsl:for-each select="session">
loop to pull out information, however that ends with me outputting duplicate dates and times.
I have no problem doing the actual date and time parsing, so I am currently outputting June 6, 2012; 10:45 with no issue, but it is being duplicated each time due to the for-each, as follows:
June 6, 2012
10:45-12:45
Session 1: Presentation 1, Presentation 2
June 6, 2012
10:45-12:45
Session 2: Presentation 3, Presentation 4
June 7, 2012:
8:45-10:45
Session 3: Presentation 5, Presentation 6
What I would like is to somehow pull out all common datetimes, for instance, get output like:
June 6, 2012:
10:45-12:45
Session 1: Presentation 1, Presentation 2
Session 2: Presentation 3, Presentation 4
June 7, 2012:
8:45-10:45
Session 3: Presentation 5, Presentation 6
For reference, here is my current implementation:
<xsl:for-each select="session">
<h4>
<!-- output to Month, DD, YYYY -->
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@starttime" />
</xsl:call-template>
</h4>
<h5>
<!-- output time -->
<xsl:call-template name="formatTime">
<xsl:with-param name="dateTime" select="@starttime" />
</xsl:call-template> -
<xsl:call-template name="formatTime">
<xsl:with-param name="dateTime" select="@endtime" />
</xsl:call-template>
</h5>
<!-- session title -->
<h5><xsl:value-of select="@name"/></h5>
<!-- presentation title -->
<xsl:for-each select="presentation">
<xsl:value-of select="@name"/><xsl:element name="br"/>
</xsl:for-each>
</xsl:for-each>
And the date-time formatter:
<!-- formatting dateTime -->
<xsl:template name="formatDate">
<xsl:param name="dateTime" />
<xsl:variable name="date" select="substring-before($dateTime, ' ')" />
<xsl:variable name="year" select="substring-before($date, '-')" />
<xsl:variable name="month" select="number(substring-before(substring-after($date, '-'), '-'))" />
<xsl:variable name="day" select="number(substring-after(substring-after($date, '-'), '-'))" />
<!-- output -->
<xsl:choose>
<xsl:when test="$month = '1'">January</xsl:when>
<xsl:when test="$month = '2'">February</xsl:when>
<xsl:when test="$month = '3'">March</xsl:when>
<xsl:when test="$month = '4'">April</xsl:when>
<xsl:when test="$month = '5'">May</xsl:when>
<xsl:when test="$month = '6'">June</xsl:when>
<xsl:when test="$month = '7'">July</xsl:when>
<xsl:when test="$month = '8'">August</xsl:when>
<xsl:when test="$month = '9'">September</xsl:when>
<xsl:when test="$month = '10'">October</xsl:when>
<xsl:when test="$month = '11'">November</xsl:when>
<xsl:when test="$month = '12'">December</xsl:when>
</xsl:choose>
<xsl:value-of select="' '" />
<xsl:value-of select="$day" />
<xsl:value-of select="', '" />
<xsl:value-of select="$year" />
</xsl:template>
<!-- formatting dateTime -->
<xsl:template name="formatTime">
<xsl:param name="dateTime" />
<xsl:value-of select="substring-after($dateTime, ' ')" />
</xsl:template>