I’m using javascript to pad numbers in my xslt file. but when debugging I get an error saying.
Extension function parameters or return values which have Clr type
‘ConcatString’ are not supported.
How can I fix this?
xslt
<xsl:template name="padNumber">
<xsl:param name="value"></xsl:param>
<xsl:param name="length"></xsl:param>
<xsl:value-of select="user:PadDigits($value,$length)"/>
</xsl:template>
javascript
function PadDigits(n, totalDigits)
{
n = n.toString();
var pd = '';
if (totalDigits > n.length)
{
var i;
for (i=0; i<(totalDigits-n.length); i++)
{
pd += '0';
}
}
pd = pd + n.toString();
return pd;
}
You don’t need an extension function for this at all.
Use this pure XSLT implementation:
Here is a complete example:
When this transformation is applied on any XML document (not used in this demo), the wanted, correct result is produced:
You can further parameterize the wanted padding character to be used:
When this transformation is performed, the result is now: