Jack Thor
Jack Thor

Reputation: 1594

Param and XSLT apply template

I am stuck. What I want to do is assign a number to a attribute in my cell. I do this by calling a template and passing a param into that template that I call.

 <xsl:call-template name="RowIdInitializer" >
    <xsl:with-param name="i">1</xsl:with-param>        
  </xsl:call-template>

I then use that param and pass it to an apply-template as a param

<xsl:template name="RowIdInitializer">
<xsl:param name="i" />   
   <xsl:apply-templates select="Data" mode="table" >
    <xsl:with-param name="iThis" select="$i"/>             
  </xsl:apply-templates>

<xsl:if test="@Exsist">
  <xsl:call-template name="RowIdInitializer">
    <xsl:with-param name="i" select="$i + 1">         
    </xsl:with-param>        
  </xsl:call-template>
</xsl:if>
</xsl:template>

Notice that I then call the template from within itself (recursive), and passed an incremented value of the param into the template as I call itself. Trying to imitate a for loop, where each data mode posses an attribute Exist (This might be a problem later, because the first call to RowIdInitializer is called from one level up where it might be looking for the Exist attribute in the Row node,

<xsl:template match="Row">
   ..... some other stuff     
  <xsl:call-template name="RowIdInitializer" >
    <xsl:with-param name="i">1</xsl:with-param>        
  </xsl:call-template>
</xsl:template>

but this is not the problem just pointing it out). The param passed on to the apply template is where it is assigned to an attribute data-swipepage.

<xsl:template select="Data" mode="table" >
 <xsl:param name="iThis" />  
<td class="dataTableCell" onblur="cellEvent(event)" data-SwipePage ="$iThis">     
 ..otherstuff...
</td>   

This is where the problem lies. The value is not being passed through, and the string literal is being assigned as the value. Such that when I go inspect the HTML in the dev console in the browser I get an attribute that says data-SwipePage ="$iThis" for all the td element created for each data node that is a child of row. I also have tried passing in a just the number one like this

<xsl:apply-templates select="Data" mode="table" >
    <xsl:with-param name="iThis" select="1"/>             
  </xsl:apply-templates>

and

<xsl:apply-templates select="Data" mode="table" >
    <xsl:with-param name="iThis">1 </xsl:with-pam>             
  </xsl:apply-templates>

I also tried using breaking the with-param for all <xsl:with-param like this

 <xsl:with-param name="iThis">
      <xsl:value-of select="$i"/>
    </xsl:with-param>

and the literal string value is still being used.

Upvotes: 0

Views: 2749

Answers (1)

kstubs
kstubs

Reputation: 808

Without fully evaluating your code, there is an obvious boo boo above, in which you need to surround your variable, $iThis, with { and } such as:

<xsl:template select="Data" mode="table" >
 <xsl:param name="iThis" />  
<td class="dataTableCell" onblur="cellEvent(event)" data-SwipePage ="{$iThis}">     
 ..otherstuff...
</td>  

Upvotes: 1

Related Questions