On 21/09/2010 6:47 PM, Meeraj Kunnumpurath wrote:

I would recommend that you go to the xsl-list at mulberrytech.com for XSLT programming advice, unless the question is specific to Saxon. However, since you asked...

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

<xsl:stylesheet version="1.0"

I would generally recommend using version="2.0" if you are using 2.0 features. This enables the processor to do stronger type-checking and thus to produce better diagnostics. In this particular case, using "1.0" was the cause of the problem. In 1.0 mode, the processor tries hard to produce results that are compatible with the behaviour of XSLT 1.0, and this includes doing all arithmetic in floating point, even when subtracting two integers.

Michael Kay


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


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

------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help