Hi,

I am using Saxon 9.2 HE. I am trying to use a user-defined function as shown below,

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:p="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:gpg="urn:gpg">

..................  
    <!-- Remittance information -->
    <xsl:template name="remittance-information">
        <xsl:variable name="initiating-party-name" select="concat('ORGBYO ', p:InitgPty/p:Nm)" />
        <xsl:variable name="number-of-lines-for-initiating-party-name" select="gpg:get-number-of-lines($initiating-party-name, 35)" as="xsd:integer" />
        <xsl:for-each select="0 to 3">
            <xsl:if test="substring($initiating-party-name, . * 35 + 1, 35)">
                <xsl:value-of select="substring($initiating-party-name, . * 35 + 1, 35)" />
                <xsl:text>&#13;&#10;</xsl:text>
            </xsl:if>
        </xsl:for-each>
        <xsl:if test="$number-of-lines-for-initiating-party-name &lt; 4">
            <xsl:variable name="unstructured-info" select="p:RmtInf/p:Ustrd" />
            <xsl:variable name="number-of-lines-for-unstructured-info" select="4 - $number-of-lines-for-initiating-party-name" as="xsd:integer" />
            <xsl:for-each select="0 to $number-of-lines-for-unstructured-info">
                <xsl:if test="substring($unstructured-info, . * 35 + 1, 35)">
                    <xsl:value-of select="substring($unstructured-info, . * 35 + 1, 35)" />
                    <xsl:text>&#13;&#10;</xsl:text>
                </xsl:if>
            </xsl:for-each>
        </xsl:if>
    </xsl:template>

    <xsl:function name="gpg:gen-number-of-lines" as="xsd:integer">
        <xsl:param name="text"/>
        <xsl:param name="line-length"/>
        <xsl:choose>
            <xsl:when test="string-length($text) mod $line-length = 0">
                <xsl:value-of select="string-length($text) idiv $line-length"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="string-length($text) idiv $line-length + 1"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:function>

</xsl;:stylesheet>

However, when I run the transformation I get the following error.

XTTE0570: Required item type of value of variable $number-of-lines-for-unstructured-info is xs:integer; supplied value has item type xs:double

I am not sure, whether this is my lack of knowledge of XSLT, I would have assumed the resulting type of subtracting an integer type from another integer type would be an integer type. Any pointers would be highly appreciated.

Kind regards
Meeraj