Project

Profile

Help

Saxon-JS: xsl:result-document inside xsl:try fails

Added by David Cramer about 5 years ago

My UI can receive an xml document as a uri-encoded, base64 encoded string passed in through a query param. I decode it (using atob()) and then call parse-xml() on the string. Everything works fine UNLESS the string is garbage/not-xml. In that case, parse-xml() understandably throws up. I wanted to wrap the whole mess in a try/catch, but this code contains a xsl:result-document. Unfortunately, when I have an xsl:result-document in the xsl:try, I get the following JavaScript error from Saxon-JS:

"XError: Cannot call xsl:result-document while evaluating variable at ..."

Is there a way gracefully recover from an attempt to parse-xml() on a non-xml string?

Regards, David


Replies (4)

Please register to reply

RE: Saxon-JS: xsl:result-document inside xsl:try fails - Added by Michael Kay about 5 years ago

Could you provide a repro for this? My guess is that the optimizer is creating a local variable for some reason, but this would depend on the exact detail of your XSLT code.

RE: Saxon-JS: xsl:result-document inside xsl:try fails - Added by David Cramer about 5 years ago

I've sent a stripped down version of the code via email.

RE: Saxon-JS: xsl:result-document inside xsl:try fails - Added by Debbie Lockett about 5 years ago

Thanks for the repro.

Rather than wrapping everything in the xsl:try, I think you should put the xsl:try inside the xsl:variable, e.g. something like:

<xsl:variable name="decodedDocinfoXML" as="node()?">
   <xsl:try select="parse-xml($decodedDocinfo)">
      <xsl:catch select="()"/>
   </xsl:try>
</xsl:variable>

Then you can just use xsl:choose to check whether the variable is a node as expected, for the different xsl:result-document outcomes.

RE: Saxon-JS: xsl:result-document inside xsl:try fails - Added by David Cramer about 5 years ago

Ah, I see. Yes, a much better approach.

Thanks!

    (1-4/4)

    Please register to reply