Search

I'm having troubles reading the content of a variable

<td>
  <xsl:variable name="minutes" select="substring-after(mytime, '.')">
</td>
<td>
  <xsl:value select="$minutes" /> <!-- this returns 'variable 'minutes' has not been declared -->
</td>

Thanks..

It's normal because each <td> contains it's own context.

Define your variable in the second <td> and it will live in that context:

<td>
    ...
</td>
<td>
    <xsl:variable name="minutes" select="substring-after(mytime, '.')">
    <xsl:value select="$minutes" /> <!-- all good -->
</td>

Thanks Vlad,
also, could it be possible to do something like this?

<xsl:for-each select="task">
<tr>
   <td><xsl:variable name="subtotal" select="fee" /></td>
</tr>
</xsl:for-each>
<tr>
<td><xsl:value-of select="sum($subtotal)"/></td>
</tr>

sum($subtotal) returns 'subtotal is undeclared', for scope reasons I believe. Is there some way to make it anyway?

Thanks..

no not quite... that doesn't make much sense...

In XSL you can only define a variable once, also that would not output the fee in the td, also the $subtotal is contextual to your for-each so cannot be used outside...

What you need is something like this

<xsl:for-each select="task">
    <tr>
       <td><xsl:value-of select="fee" /></td>
    </tr>
</xsl:for-each>
<tr>
    <td><xsl:value-of select="sum(task/fee)"/></td>
</tr>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details