In XSLT is it possible to use the value of an xpath expression in a call to a template using an par

Posted by Cell on Stack Overflow See other posts from Stack Overflow or by Cell
Published on 2010-01-10T18:44:41Z Indexed on 2010/03/29 1:03 UTC
Read the original article Hit count: 359

Filed under:
|

I am performing an xsl transform and in it I call a template with a param using the following code

<xsl:call-template name="GenerateColumns">
     <xsl:with-param name="curRow" select="$curRow"/>
     <xsl:with-param name="curCol" select="$curCol + 1"/>
</xsl:call-template>

This calls a template function which outputs part of a table element in HTML. The curRow and curCol are used to determine which row and column we are in the table. gbl_maxCols is set to the number of columns in an html table

<xsl:template name="GenerateColumns">
   <xsl:when test="$curCol &lt;= $gbl_maxCols">
       <td>
       <xsl:attribute="colspan">
           <xsl:value-of select="/page/column/@skipColumns"/>
       </xsl:attribute> 
   </xsl:when>
</xsl:template>

The result of this function is a set of td elements, however some of these elements (those with a skipColumn attribute greater than 1 span more than 1 column, I need to skip this many columns with the next call to generateColumns.

this works just like I would expect in the case where I simply increment the curCol param but I have a case where I need to use the value from the xml attribute skipColumns in the math to calculate the value for curCol. In the above case I iterate through all the columns and this works for the majority of my use cases. However in same cases I need to skip over some of the columns and need to pass in that value from the xml attribute to calculate how many columns I need to skip.

My naive first attempt was something like this

<xsl:call-template name="GenerateColumns">
     <xsl:with-param name="curRow" select="$curRow"/>
     <xsl:with-param name="curCol" select="$curCol + /page/column/@skipColumns"/>
</xsl:call-template>

But unforutnately this does not seem to work. Is there any way to use an attribute from an xml page in the calculation for the value of a param in xsl.

My xml page is something like this (edited heavily since the xml file is rather large)

<page>
 <column name="blank" skipColumns="1"/>
 <column name="blank" skipColumns="1"/>
 <column name="test" skipColumns="3"/>
 <column name="blank" skipColumns="1"/>
 <column name="test2" skipColumns="6"/>
</page>

after all of this I would like to have a set of td elements like the following

<td></td><td></td><td colSpan="3"></td><td></td><td colSpan="6"></td>

if I just iterate through the columns I instead end up with something like this which gives me more td elements than I should have

<td></td><td></td><td colSpan="3"></td><td></td><td colSpan="6"></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>

Edited to provide more information

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt