I guess it is a misunderstanding of the word as - I
have been reading this as 'treat the in coming value AS a ...'. It might
have been better to have used 'is' or even 'type'.
If I think of is as a declaration I still find the
fact that <xsl:param
name="logLevel" as="xsd:integer">1</xsl:param> does not work as the value 1 is not surrounded by spaces and does
convert naturally to the type defined so why not allow
I agree about the string typing arguments - but the
statement above to my eye does not contravene them.
Think of the "as" as being like the declaration of a
variable in Java
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
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.
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.
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
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"
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
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>
up the parameters in Java I pass in a value as a string.
Can you please