1

I have a parameter which currently is read from a file:

<xsl:param name="source" select="document('filename.xml')" />

but now I need to replace it with a string containing xml that comes from external source, and I get an error

XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:string`

Unfortunately I cannot use saxon's exsl:node-set() function, for business reasons I have to use version that doesn't support it. Is it possible to get node() from string in some other way?

4
  • "business reasons" meaning that you are using the free version (Saxon HE) because the business is unwilling to pay for Saxon PE or EE? Commented Feb 29, 2020 at 19:29
  • 1
    I read that exsl is included even in saxon-he version starting from 9.5 or 9.6, but business uses 9.3 and the project is ~9 years old. Upgrade is not really feasible. Commented Feb 29, 2020 at 19:33
  • The exsl:node-set() function will not convert a string to a node tree. Please show a minimal reproducible example. Commented Feb 29, 2020 at 19:48
  • Well, that is unfortunate. Upgrading the Saxon jar would be the easiest way to achieve what you want. Plus, with XSLT 3.0, there is a standard function fn:parse-xml() but requires 9.6 or greater saxonica.com/html/documentation/functions/fn/parse-xml.html Commented Feb 29, 2020 at 19:48

2 Answers 2

1

Firstly, the process of "converting a string to a node" is usually called parsing, and calling the process by its proper name might help to find the right solution.

You're in an xsl:param, which means you're on the boundary/interface between the XSLT processor and the outside world, and that presumably means you have the option of doing the parsing on either side of the boundary. If you aren't able to use the XSLT 3.0 function parse-xml() or a Saxon extension function that pre-dates it, then the best option seems to be to do the parsing in the calling application and supply the resulting node as the parameter value.

The exsl:node-set() function is defined to convert a "result tree fragment" (not a string) into a node-set. I believe some implementations of it will do parsing if supplied with a string rather than an RTF but that has never been true of the Saxon implementation. For many years Saxon has had an extension function saxon:parse() whose functionality is very close to fn:parse-xml().

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

1 Comment

Thanks for suggestion. I was able to set node as parameter on camel exchange. Saxon was able to use it correctly.
0

Why not externalize the process for converting the string into XML? Create a proxy service that is used to fetch the external String and convert into an XML response. Then, you can request the XML from your proxy service:

<xsl:param name="source" select="document('http://localhost/myCustomProxyService?file=filename.xml')"/>

2 Comments

if that changes anything my external source is a header of camel exchange. I'm not sure if it's possible to just dump it into the file and then read in xslt given that this system can get many messages in a short time.
Another option would be to dynamically generate an XSLT with the XML from the header inline in the param or variable declaration. Execute the dynamically generated XSLT instead.

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.