How to subtract value in xslt?

10,870

Solution 1

The problem is that hyphens are valid in variable names, so when you do this...

<xsl:variable name="tCurpg" select="($currentCurpg-1)"/>

It is literally looking for a variable named currentCurpg-1.

Instead change it to this...

<xsl:variable name="tCurpg" select="$currentCurpg - 1"/>

Solution 2

Looking at your code, the curly {} braces around your variable are not need in an xslt statement only in html

eg div title="{$currentCurpg}">

so in your code you need

<xsl:for-each select="ul/li[position() &gt;= (last()-$currentCurpg) and position() &lt;= last()-1]">

Updated Based on your updated code you need to drop the () and put spaces between the variable and the - 1 like this

 <xsl:variable name="tCurpg" select="$currentCurpg - 1"/>
Share:
10,870
user944513
Author by

user944513

Updated on June 09, 2022

Comments

  • user944513
    user944513 almost 2 years

    Could you please tell me how to subtract value in xslt using a variable?

    Here is my code:

    <xsl:variable name="currentCurpg" select="1"/>
    <xsl:variable name="tCurpg" select="($currentCurpg-1)"/>
    

    The variable tCurpg should be zero or 0.

    Why I am getting error?

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
    
        <xsl:template match="/">
          <hmtl>
            <head>
              <title>New Version!</title>
            </head>
             <xsl:variable name="currentCurpg" select="1"/>
              <xsl:variable name="tCurpg" select="($currentCurpg-1)"/>
         <xsl:value-of select="$tCurpg"/>
    
          </hmtl>
        </xsl:template>
    
    
    </xsl:transform>
    

    I am expecting output zero.