Invalid coercion: () as xs:string in xdmp:xslt-eval

390 views Asked by At

I am making use of MarkLogic's ability to call XQuery functions in the XSL transform.

Let's say I have an XQuery library with a function whose signature looks like the following. This is for illustrative purposes only.

declare function my-func:ex-join($first as xs:string, $last as xs:string) as xs:string
{
  fn:concat($first, '-', $last)
}

From XQuery, I can call this function with empty sequence as parameters, with no issues, i.e.

ex-join((), '1244')

The function will just return an empty sequence, but I don't get any errors. If I try to all this function from with in my XSL transform,as in:

<xsl:value-of select="my-func:ex-join(//node/value/text(), 'something')"/>

If the /node/value does not exist, and an empty sequence is passed in, I get the coercion error.

Does anyone have suggestions to work around the coercion problem, outside of checking the values in XSL prior to the select? These are auto-generated XSL templates, which would mean a lot of coded checks.

Thanks,

-tj

1

There are 1 answers

0
grtjn On BEST ANSWER

Attempts to invoke that function in XQuery would fail too. It is probably due to function mapping that you don't notice this though. Put the following at the top of your XQuery code:

declare option xdmp:mapping "false";

Next to this, you only need to change the signature of your function to accept empty-sequences. Replace as xs:string with as xs:string?:

declare function my-func:ex-join($first as xs:string?, $last as xs:string?) as xs:string

fn:concat will accept empty sequences as arguments, so no further changes required to make it work..

HTH!