Re: Xpath try catch not allowed in XSLT?

Martin Honnen <[email protected]> Sun, 13 Sep 2020 20:21:29 +0200
Newsgroups gmane.text.xml.saxon.help
Organization Liberty Development
Message-ID <[email protected]>
On 13.09.2020 20:09, Ihe Onwuka wrote:
> Error near {... (try {key} at char 73 in xsl:element/@namespace on line
> 98 column 55 of translator.xsl:
>    XPST0003  try/catch expressions are not allowed in XPath
>
> I am running Saxon 10.2
>
> My use case was wanting to use the zero-or-one XPath function which does
> exactly what I want but returns an error where I want an empty () node
> returned.
>
> hence
>
>   try {zero-or-one($someSequence)}
>          catch * {()}

XSLT and XQuery have try/catch, XPath not; XQuery has it as an
expression, XSLT as element instructions. I think you get that
particular error from Saxon as it supports try/catch expressions in
XQuery.  In XSLT you need to use the xsl:try/xsl:catch element
instructions https://www.w3.org/TR/xslt-30/#try-catch e.g.

    <xsl:try select="zero-or-one($someSequence)">
      <xsl:catch errors="*" select="()"/>
    </xsl:try>


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help