I think you've hit a problem that Saxon is not actually checking the
type of supplied stylesheet parameters against their declaration at the
moment. If you are calling Saxon from the command line, then the
supplied parameter is always a string, regardless of the xsl:param
declaration.
The answer is to declare it as a string, and convert it to an integer
using a casting function:
<xsl:param name="pos-as-string"/>
<xsl:variable name="pos-as-integer"
select="xs:integer($pos-as-string)"/>
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Clay Redding
Sent: 18 June 2003 18:21
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Inserting global parameter value into xsl:function
Hi list, I am somewhat of an XSL 2.0 newbie, and I have a
fairly simple
question that doesn't necessarily have anything to do with 2.0, but
involves the xsl:function element.
In my XSL I have defined a function that will take a
required, top-level
parameter (called 'position'), and then feeds this position into a
variable (called 'forward') that calls the function
('forwardURL') with
the 'postion' parameter as the value that references the
value I need.
The function is used to return a URL value from the XML doc.
That URL
should be available for referencing later in the HTML output
through the
'forward' global attribute.
Whenever I try to invoke the code below, it chokes on data typing
issues, saying that it cannot add xs:string to xs:integer.
What it is
trying to do is take the ($position) reference in the
"forward" variable
and add it within the function to 1. But it's treating
$position as a
string, not as an integer passed on as a value. How can I reference
$position (or any other variable/parameter) within a
select/XPath-esque
attribute so that it doesn't treat $position as a literal
string? Do I
use curly braces, brackets, or what?
I'm using Saxon 7.5.1 as servlet, with JDK 1.4.1.
Thanks for any help you can give.
Clay
<xsl:stylesheet version="2.0" xmlns:njp="http://...,etc."
xmlns:xs="http://...,etc." xmlns:mets="http://..., etc.">
<!-- shortened for brevity -->
<xsl:param name="position" required="yes" as="xs:integer"/>
<xsl:variable name="forward" as="xs:string"
select="njp:forwardURL($position)"/>
<xsl:variable name="array">
<xsl:for-each
select="mets:mets/mets:fileSec/mets:fileGrp/mets:file/mets:FLocat">
<id><xsl:value-of select="@ID"/></id>
<url><xsl:value-of select="@xlink:href"/></url>
<position><xsl:value-of select="position() - 1"/></position>
</xsl:for-each>
<xsl:for-each select="$dmdSec">
<dmd><xsl:value-of select="."/></dmd>
</xsl:for-each>
</xsl:variable>
<xsl:function name="njp:forwardURL">
<xsl:param name="placeholder"/>
<xsl:sequence select="$array/url[$placeholder + 1]"/>
</xsl:function>
...
<!-- the following appears within an xsl:template -->
<img id="mypic" class="border" alt="Page" src="{$forward}"/>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list