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

Re: How to calculate rowspan?

Subject: Re: How to calculate rowspan?
From: "cking" <cking@xxxxxxxxxx>
Date: Thu, 26 Aug 2004 22:08:58 +0200
xsl rowspan
Hi Anton

> Unfortunatly they aren't unique... 

OK... I made a recursive template to calculate the rowspan.
This should work correctly, also in the AAABBA case!

 ... context of COL0 | COL1 | COL2 | COL3 (in xsl:template or xsl:for-each) ...
  <xsl:choose>
   <xsl:when test="@Type='Dimesion'">
    <xsl:variable name="pos" select="position()"/>
    <xsl:variable name="val" select="."/>
    <xsl:if test="not(../preceding-sibling::*[1]/*[$pos and .=$val])">
     <xsl:variable name="rowspan">
      <xsl:apply-templates select="." mode="calc-rowspan"/>
     </xsl:variable>
     <td rowspan="{$rowspan}">
      <xsl:value-of select="."/>
     </td>
    </xsl:if>
   </xsl:when>
   <xsl:otherwise>
    <td>
     <xsl:value-of select="."/>
    </td>
   </xsl:otherwise>
  </xsl:choose>
 ...

 <xsl:template match="*" mode="calc-rowspan">
  <xsl:param name="i" select="1"/>
  <xsl:variable name="pos" select="position()"/>
  <xsl:variable name="val" select="."/>
  <xsl:variable name="next" select="../following-sibling::*[1]/*[$pos and .=$val]"/>
  <xsl:choose>
   <xsl:when test="$next">
    <xsl:apply-templates select="$next" mode="calc-rowspan">
     <xsl:with-param name="i" select="$i + 1"/>
    </xsl:apply-templates>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select="$i"/></xsl:otherwise>
  </xsl:choose>
 </xsl:template>

BTW. do you have control over your input files? If so, consider
using one element name for the columns, ie:

 <ROW>
  <COL Type="Dimesion">A</COL>
  <COL Type="Dimesion">E</COL>
  <COL>1</COL>
  <COL>2</COL>
 </ROW>

rather than

 <ROW>
  <COL0 Type="Dimesion">A</COL0>
  <COL1 Type="Dimesion">E</COL1>
  <COL2>1</COL2>
  <COL3>2</COL3>
 </ROW>

Then you can select and match "COL" instead of "*" 
(the column index is taken from its position, anyway)

HTH,
Anton Triest

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.