[xsl] Using a sequence of years to select documents to display in a table row

Subject: [xsl] Using a sequence of years to select documents to display in a table row
From: "Michael Tracey Zellmann" <tracey.zellmann@xxxxxxxxx>
Date: Fri, 23 Nov 2007 15:43:57 -0500
I have an XML source document that contains elements describing
historic documents. Each <document> has a <year>, and a <title> along
with other elements. There may be multiple documents for each year.
There are documents that relate to Selectmen Reports and ones that
relate to School Committee reports. I want to build an HTML table with
one row for each year. The first column is the year, the second would
be the titles of the Selectmen material and the third column the
titles of the School Committee material. I can identify School
committee material if the <title> content contains 'Selectmen'
Similarly, I can identify School Committee material if the <title>
contains 'School'.

I have a working solution, but I don't think it makes good use of the language.

The years right now extend from 1842 through 1862.

I tried
<xsl:for-each select="1842 to 1862">
     <tr><td><xsl:value-of select="."/></td>
     <td>
        <xsl:apply-templates select="documents/document[year = . and
contains(title, 'Selectmen')"/>
    </td>
    <td>
        <xsl:apply-templates select="documents/document[year = . and
contains(title, 'School')"/>
    </td>
    </tr>
</xsl:for-each>

The template that matches document just displays the value of each
title element followed by a <br />

But, I get an error that I can't use documents in that way because the
context is atomic.

I was able to get the following to work, basically hand-coding one row
for each of the year values.

<tr><td>1859</td>
      <td><xsl:apply-templates select="documents/document[year = 1859
and contains(title, 'Selectmen')]"/></td>
      <td><xsl:apply-templates select="documents/document[year = 1859
and contains(title, 'School')]"/></td>
</tr>

(repeat this for each year)

But there must be a direct way to do this with the language.

Current Thread