[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: table formating

Subject: Re: table formating
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jan 2011 14:20:29 +0000
Re:  table formating
On 26/01/2011 14:08, Michael Kay wrote:
Do a preprocessing pass to add an @index attribute to all cells.

Identity template plus

<xsl:template match="row">
<xsl:for-each-group select="cell" group-starting-with="cell[@index]">
<xsl:for-each select="current-group()">
<cell index="{current-group()[1]/@index + position() - 1}">
<xsl:copy-of select="child::node()"/>
</
</
</
</

Sorry, that's the answer to a slightly different question - but one that's often useful in this kind of situation.

For your problem I'd be inclined to use sibling recursion:

<xsl:template match="row">
<xsl:apply-templates select="cell[1]" mode="add-missing-cells">
<xsl:wirh-param name="present-in-output select="0"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="cell" mode="add-missing-cells" priority="1">
<xsl:with-param name="present-in-output" as="xs:integer"/>
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::cell[1]" mode="add-missing-cells">
<xsl:with-param name="present-in-output select="$present-in-output+1"/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="cell[@index]" mode="add-missing-cells" priority="2">
<xsl:wirh-param name="present-in-output" as="xs:integer"/>
<xsl:variable name="missing" select="@index - ($present-in-output + 1)" as="xs:integer"/>
<xsl:for-each select="1 to $missing"><cell/></xsl:for-each>
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::cell[1]" mode="add-missing-cells">
<xsl:with-param name="present-in-output select="$present-in-output+$missing+1"/>
</xsl:apply-templates>
</xsl:template>


Michael Kay
Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.