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...
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"

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
Saxonica

                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



------------------------------------------------------------------------------ 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