Altova Mailing List Archives


RE: [xsl] XSLT 2.0 and external parameters: a string -> xsd:integer. How?

From: "Michael Kay" <mhk@--------->
To:
Date: 5/20/2003 11:54:00 AM
> 
> I guess this is another angle on the typing questions that have been 
> floating around the list recently.
> 
> Code that worked with Saxon 7.4 (and that I think would work 
> in XSLT 1.0) 
> is now broken with Saxon 7.5.
> 
> How can I supply an external parameter to a Saxon 7.5 
> stylesheet which is 
> $number and has an integer value and get the XSLT processor 
> to treat it as 
> an xsd:integer. Well, I don't particularly want the parameter to be 
> xsd:integer but I assume I won't be able to do anything 
> numeric with it, 
> unless I make it explicitly numeric.

If you are passing parameters from a JAXP application, you can pass a
Java Integer.

If you want to do it from the command line, you can only pass strings;
you will have to convert the string to an integer within your own code
(this is exactly the same as writing a Java application that reads
arguments from the command line - they arrive as strings).
> 
> If I try to ignore types altogether Saxon 7.5 complains, not 
> surprisingly, 
> that it cannot compare xsd:string to xsd:integer. If there is 
> a way to 
> write a type-agnostic stylesheet to accept a parameter that 
> is intended to 
> be numeric it isn't obvious to me at the moment.

Write:

<xsl:param name="p" as="xs:string"/>
<xsl:variable name="p-as-int" as="xs:integer" select="xs:integer($p)"/>


> 
> So I made the input parameter xsd:string and created a new numeric 
> parameter using the xsd:integer() constructor function. Same 
> error message.
> 
> Then I tried making the input parameter xdt:untypedAtomic with the 
> xsd:integer() constructor function to create the second 
> parameter.  Same 
> error message.
> 
> Then I tried adding an as="xsd:integer". Same error message.

I'm afraid it's difficult to tell from this description exactly what you
did, and exactly what messages you got.
> 
> The Saxon 7.5 documentation indicates that "most" such functions are 
> supported. Is this one unsupported or am I missing a basic 
> trick somewhere?

I think you missed a trick somewhere, but from the description I can't
tell where.


Michael Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.