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() &lt; 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

Go to topic 5942

Return to index page 210
Return to index page 209
Return to index page 208
Return to index page 207
Return to index page 206
Return to index page 205
Return to index page 204
Return to index page 203
Return to index page 202
Return to index page 201