|
Subject:
|
XSLT Row replication in Tables
|
|
Posted By:
|
jsuen
|
Post Date:
|
8/6/2006 11:57:10 PM
|
Hi,
I wanted to generate a table with a new row (tr) replicated every 4 or so elements (td's). I have found a good example using a calendar month as a data source, and would like the same design principle in my XSLT.
i.e. for:
<Month>
<day date="1"/>
<day date="2"/>
<day date="3"/>
<day date="4"/>
<day date="5"/>
<day date="6"/>
<day date="7"/>
<day date="8"/>
<day date="9"/>
</Month>
The template applied is:
<xsl:template match="day[position() mod 4 = 1]">
<tr>
<xsl:for-each select=". | following-sibling::day[position() < 4]">
<td><xsl:value-of select="@date"/></td>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template match="day"/> <!-- ignore the other days -->
The only problem in my application is that I want to fetch the datasource from a http: XML document (i.e. via localhost). Is it possible to do this in the code example above?
I cannot reference the $variable in the <xsl:template match=""> tag, but normally use a variable to assign the external XML datasource to be used.
Any help would be greatly appreciated, thanks
Jon
|
|
Reply By:
|
mhkay
|
Reply Date:
|
8/7/2006 11:07:33 AM
|
Your template rules look fine, you just need to apply them at some point in your code using an instruction such as
<xsl:apply-templates select="document('lookup.xml')/dates/date"/>
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|