xsl-list
[Top] [All Lists]

Re: [xsl] Signature of a function that may throw an error

2019-01-22 10:37:17
I tried Christophe’s function with several Saxon versions, from 9.5 to 9.9, HE and PE, and also XSLT versions 2.0 and 3.0 where available. I slightly changed the error() invocation, using a QName that was in a namespace I was using in the stylesheet at hand. I could only reproduce the message that Christophe was seeing when I returned an empty sequence instead of error(…). Therefore I can corroborate what you are saying, Michael, at least for my setup.

On 22.01.2019 17:28, Michael Kay mike(_at_)saxonica(_dot_)com wrote:
The XPath spec defines the return type of the error() function as "none", and the role of "none" in the type system is pretty much unspecified. As a result, there was always a steady stream of problems with edge cases in the W3C test suites in this area.

Saxon actually implements the static return type of error() as item(), which is intended to ensure that you won't get a static type error from this sort of construct.

This particular example doesn't seem to give a static error with Saxon 9.9, though the error message looks like it comes from Saxon. The code that produces this error is intended for the case where one of the branches of the conditional always returns an empty sequence (typically, an implicit xsl:otherwise).

What software version are you running?

Michael Kay
Saxonica



On 22 Jan 2019, at 14:36, Christophe Marchand cmarchand(_at_)oxiane(_dot_)com <mailto:cmarchand(_at_)oxiane(_dot_)com> <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

Hello,

I have a function that must return a xs:string, or raise an error, if result value can not be computed, or is empty-sequence.

Here is function :

  <xsl:function name="conf:getConfVar" as="xs:string">
    <xsl:param name="conf" as="element(els-conf:conf)"/>
    <xsl:param name="varName" as="xs:string"/>
    <xsl:sequence select="
      if (exists($conf/els-conf:variable[@name=$varName]))
      then $conf/els-conf:variable[@name=$varName]/@value
      else (
        error(
          $conf:ERROR_MISSING_ENTRY,
          concat('Entry ',$varName,' is missing in environment configuration')
        )
      )
      "/>
  </xsl:function>

When a variable does not exist in $conf, I expect an error being raised, and expect to catch it in a xsl:try / xsl:catch.

But, in this case, I get this :

XTTE0780: Conditional expression: The condition is not satisfied, so an empty sequence is returned, but this is not allowed as the result of call to conf:getConfVar
in xsl:sequence/@select ....

  * I understand that error() function never return a value, so return
    value does not satisfies xsl:function/@as constrint. Is it correct ?
  * How could I write this, as I want the return type being xs:string,
    and not xs:string?, and I want my error to be raised when entry is
    missing ?

Best regards,
Christophe

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by email)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/225679> (by email <>)

--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>