1

I am currently trying to transform a larger stack of XML documents with XSLT and am using a shell-script to do so. However, I am getting the following error:

The only value that can pass type-checking is an empty sequence. Required item type of first argument of contains() is xs:string; supplied value has item type xs:anyURI

When I tracked down the corresponding lines in the xsl, it turned out that this is probably due to a variable which is defined in another script. Its definition looks like this:

<xsl:variable name="crturi" select="document-uri(/)"/>

So does my error message mean that I somehow need to convert the value of $crturi to thr string format before it can be processed?

4
  • What product are you using? It looks like a Saxon error message: perhaps it's an old release of Saxon dating from before URI-to-string promotion was implemented? Commented Aug 17, 2014 at 15:22
  • Thank you for your reply. I am not exactly sure which Saxon version I am using that the moment, because I could not find a command to find out, but since the latest version in my download folder is HE 9.5.1.6, I think that I installed that one. It seems to have been a one-day-only issue though since everything is working fine now. Commented Aug 18, 2014 at 17:35
  • To find out which Saxon version you are using, run with the -t option on the command line, or put the result of system-property('xsl:product-version') in a message, or in a comment node in your transformation output. Commented Aug 18, 2014 at 22:52
  • Thank you. I am using the Saxon-HE 9.5.1.6J version. We are currently trying to reproduce the error message but are not sure what might have caused it. I'll post again if we manage to write a minimal example. Commented Aug 19, 2014 at 14:16

2 Answers 2

2

You should simply be able to use string($crturi) as an argument to the contains function.

Sign up to request clarification or add additional context in comments.

Comments

1

The type xs:anyURI is automatically convertible to xs:string through a concept called type promotion. The error you get seems to be a bug in the product you are using. From the XPath spec, quote:

A value of type xs:anyURI (or any type derived by restriction from xs:anyURI) can be promoted to the type xs:string.

The resolution of Martin Honnen will solve it in your situation, but you should consider raising a bug against the processor. Alternatively, you can use $crturi treat as xs:string, but this too is just a workaround the bug.

I tried the following example with Exselt and Saxon and neither threw an error (as expected).

<xsl:template match="/">
    <xsl:value-of select="contains(document-uri(/), 'any')" />
</xsl:template>

3 Comments

Thank you very much for your answer. I still do not know what's been going on since the error seems to have been a one day thing. It appeared three times on the day I was posting the question while it is totally gone now and even my initial markup works. Maybe, it could be due to me moving the variable declaration to the stylesheet where the variable is being used. However, they were linked from the start so I don't think that it would have been necessary.
Also, I would like to upvote both of the answers but sadly I cannot do so since I don't have enough reputation yet.
@aerdureth: If you do encounter it again, and have it reproducible, then consider posting it as a bug report to the vendors of your processor. You can upvote after 15pts, I think, which is probably after your next question on SO ;).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.