Re: [xsl] Why does the addition of one (1) to a positiveInteger produce an integer?

Subject: Re: [xsl] Why does the addition of one (1) to a positiveInteger produce an integer?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 29 Aug 2010 16:43:48 -0400
At 2010-08-29 15:43 -0400, Costello, Roger L. wrote:
I have a function that has a parameter with a xs:positiveInteger datatype. Within the function I add one (1) to the parameter:

<xsl:function name="f:iter">
    <xsl:param name="count" as="xs:positiveInteger" />

...

<xsl:sequence select="f:iter($count + 1)" />

</xsl:function>

When I run this I get an error, "The argument to f:iter is xs:positiveInteger, the supplied value is xs:integer"

What is the rationale for this? After all, if I add one (1) to any positiveInteger the result must be a positiveInteger.

False. An integer *type* is more general than the positiveInteger *type*, thus when you add the two the result is the more general of the two, which is integer. And since the integer is too general for the parameter type, there is the error.


So, not only do you need:

<xsl:sequence select="f:iter($count + xs:positiveInteger(1))" />

.... but wherever you are calling f:iter() for the first time, if you are doing:

<xsl:value-of select="f:iter(3)"/>

.... you will get the same problem and you need to say:

<xsl:value-of select="f:iter(xs:positiveInteger(3))"/>

I hope this helps.

. . . . . . . . . . Ken

--
XSLT/XQuery training:   after http://XMLPrague.cz 2011-03-28/04-01
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread