Re: Bug 4378: absent context item

On 09/11/2015 15:00, Michael Kay wrote:


>>> Omitting a global-context-item declaration [in XSLT] is equivalent 
>>> to specifying
>>>
>>>> <xsl:global-context-item use=“optional" as="item()" />
>>> This declaration defines the set of possible states of the context 
>>> item to include any item, plus absence.
>>>
>>> I don’t find the notion of the static type being “absent” helpful 
>>> without a clear understanding of what the absence of a static type 
>>> tells us about the set of possible dynamic states.
>> It tells us nothing about the possible dynamic states, because it 
>> identifies a static error.
> No, the declaration <xsl:global-context-item use=“optional" 
> as="item()" /> says (a) if you supply a global context item then it 
> must be an item (trivially true), and (b) if you don't supply a global 
> context item then any reference to "." (etc) is a dynamic error XPDY0002.
>
> We can raise the error statically if you specify use="required", but 
> not if you leave it at the default use="optional".
>
> We allow users to write:
>
> <xsl:variable name="context-item-if-supplied" as="item()?">
>    <xsl:try select=".">
>     <xsl:catch errors="*:XPDY0002" select="()"/>
>   </xsl:try>
> </xsl:variable>
>
> I'm reluctant to lose that capability.

You won't lose that (unless the above appears within a function, since 
the context item isn't in scope inside the function).  As I've said, the 
global-context-item makes it absolutely clear that the context item 
static type is not absent.

Cheers,
     Tim

Received on Monday, 9 November 2015 16:01:34 UTC