I need to check the length of a field and then add .
before last two
digits.
Example: the value of Amount
is 0001234567
, to be replaced as 00012345.67
. Here string length will be 10.
But the command fails and is not able to retrieve the value from
($VARAmtLength-2)
or ($VARAmtLength-1)
.
My code as below:
<xsl:variable name="VARAmtLength" select="string-length (ns0:Amount )"/>
<xsl:if test=" ($VARAmtLength> 0)">
<tns:Amount>
<xsl:value-of select="concat(substring(ns0:Amount, 1, ($VARAmtLength- 2)),'.', substring(ns0:Amount, ($VARAmtLength-1, 2)))"/>
</tns:Amount>
</xsl:if>
Any help?
I think your code is working fine.
Just replace this line with existing one:
<xsl:value-of select="concat(substring(ns0:Amount, 1, ($VARAmtLength - 2)),'.', substring(ns0:Amount, ($VARAmtLength - 1), 2))" />
1. There should be a space around subtraction operator '-'. Otherwise it will consider $VARAmtLength-
as variable name.
2. You had misplaced round parentheses for second substring()
function.