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
.
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"/>
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() >= (last()-$currentCurpg) and position() <= 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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With