Think of the "as" as being like the declaration of a variable in Java
 
String s;
 
This doesn't mean "if someone assigns a number to s, convert it to a string". It means "if someone assigns a number to s, report an error".
 
There are arguments for strong typing in programming languages and arguments for weak typing, and this probably isn't the best forum to conduct them! XSLT tries to get the best of both worlds with the concept of "untyped atomic", but I agree the balance isn't always perfect. However, I do find that declaring the types of variables and parameters catches a very large number of my sillier programming mistakes.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 18 July 2008 15:19
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] Error with parameters

Thanks for this answer.  It does not seem terribly intuitive.  After all by supplying an 'as' attribute I am telling the processor what I expect the contents to be treated as.
 
Martin


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Michael Kay
Sent: 18 July 2008 15:01
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] Error with parameters

The rules here are the same as the rules for function calling: if a function expects an integer, then you can pass it an integer, or an untypedAtomic value, or a node containing an integer or an untypedAtomic value, but you can't pass it (for example) a string or a double.
 
Either pass an integer as the value, or pass an untypedAtomic value (this is what happens from the command line), or declare the parameter as being of type string, and convert it to an integer by casting, that is xs:integer($param).
 
Also, I would suggest getting into the habit of writing this kind of thing as
 
<xsl:param name="logLevel" as="xs:integer" select="1"/>
 
It's much more direct, and in some cases much more efficient, to initialize the value to the integer 1, rather than to a document node containing a text node containing the string representation of the number 1.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 18 July 2008 13:37
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Error with parameters

Hi, 
 
 I am getting a "Cannot promote non-numeric value to xs:integer" with a parameter value. The parameter definition looks like this:
 
    <xsl:param name="logLevel" as="xsd:integer">1</xsl:param>
 
  When setting up the parameters in Java I pass in a value as a string.
 
Can you please help?
 
Martin