XSLT Row Replication within Tables
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Mon Aug 07, 2006 7:16 am
XSLT Row Replication within Tables
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:
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
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:
Code: Select all
<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>
Code: Select all
<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 -->
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
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
Assuming you have the data in some variable then you can match on the document root element and apply templates on that variable content. You can also use the document function to access the data and again match on the document root and apply templates on the nodes in the document, like:
Best Regards,
George
Assuming you have the data in some variable then you can match on the document root element and apply templates on that variable content. You can also use the document function to access the data and again match on the document root and apply templates on the nodes in the document, like:
Code: Select all
<xsl:template match="/">
<xsl:apply-templates select="document('http://localhost/myData.xml')/*"/>
</xsl:template>
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service