[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2007-11-23 15:43 -0500, Michael Tracey Zellmann wrote:
Correct ... the context item for the for-each is a number, it is not a document node, so *any* XPath location path address of nodes is going to fail because it doesn't know which document tree of nodes you want to look in.
Indeed: put your document nodes into a variable and then index off of the variable when your context node is a number:
I hope this helps.
. . . . . . . . . . . . Ken
Re: [xsl] Using a sequence of years to select documents to display in a table row
Subject: Re: [xsl] Using a sequence of years to select documents to display in a table row From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 23 Nov 2007 16:20:44 -0500 |
At 2007-11-23 15:43 -0500, Michael Tracey Zellmann wrote:
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.
Correct ... the context item for the for-each is a number, it is not a document node, so *any* XPath location path address of nodes is going to fail because it doesn't know which document tree of nodes you want to look in.
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.
Indeed: put your document nodes into a variable and then index off of the variable when your context node is a number:
<xsl:variable name="docs" select="documents/document"/> <xsl:for-each select="1842 to 1862"> <tr><td><xsl:value-of select="."/></td> <td> <xsl:apply-templates select="$docs[year = . and contains(title, 'Selectmen')"/> </td> <td> <xsl:apply-templates select="$docs[year = . and contains(title, 'School')"/> </td> </tr> </xsl:for-each>
I hope this helps.
. . . . . . . . . . . . Ken
-- Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Using a sequence of years to , Michael Tracey Zellm | Thread | RE: [xsl] Using a sequence of years, Michael Kay |
[xsl] xsl:for-each-group output con, Andreas Peter | Date | Re: [xsl] xsl:for-each-group output, G. Ken Holman |
Month |