This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29705 - [xslt3.0] global-context-item() function
Summary: [xslt3.0] global-context-item() function
Status: CLOSED WONTFIX
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 3.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-25 15:47 UTC by Michael Kay
Modified: 2016-10-06 18:42 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2016-06-25 15:47:43 UTC
Would it be useful to have a function

global-context-item()

to return the value of the global context item (or () if absent)?

Firstly it saves the user the trouble of binding a global variable

<xsl:variable name="source" select="."/>

Secondly it provides a way of determining (without try/catch) whether a global context item was actually supplied, by testing 

exists(global-context-item())

In Saxon-CE and Saxon-JS we have a vendor extension function ixsl:source() with this meaning; it would be nice to be able to use a core function instead.
Comment 1 Abel Braaksma 2016-06-28 08:31:41 UTC
I'd agree, considering that you have an extension function for this suggests there are users asking for it. Furthermore, since we agreed in a different bug that the global context item cannot be streamed (that is, from the point of the streamability rules it is always grounded), the streamability rules for this function are trivial.
Comment 2 Michael Kay 2016-06-30 17:22:48 UTC
In discussion, Abel pointed out that this would also suggest we should provide initial-match-selection() - perhaps disallowing this if the IMS contains streamed nodes.

MK noted that this would be a significant departure in that there is currently no way to ask, for example "how many items are there in the initial match selection"? - you can only process the items one at a time.
Comment 3 Michael Kay 2016-07-06 22:59:27 UTC
I'm inclined to resist the addition of initial-match-selection(). I can certainly see a case for it, but 

(a) the interaction with streaming creates some messy restrictions;

(b) the existence of the function also prevents some optimizations that are otherwise possible; for example consider the case where the initial match selection is a sequence of 5000 document nodes. At present these can be processed one at a time, and there is no need to keep any of the documents in memory once processing has moved on to the next one. If initial-match-selection() is available, a processor might need to keep the documents in memory just in case initial-match-selection() is called.
Comment 4 Abel Braaksma 2016-07-07 00:35:10 UTC
Did you happen to have seen or read my suggestion in https://lists.w3.org/Archives/Public/public-xsl-wg/2016Jul/0000.html (public archive)?

Herein I propose to create a function similar to fn:current. I agree to both (a) and (b) below, but if you can only access the *current* item in the initial match selection, there is no implementation problem w.r.t. performance, and the streamability rules are trivial (climbing posture).

That way we don't even need the function fn:global-context-item(), as we cover the use-case, and if GCI is different from IMS, the user can still use the old-style approach.
Comment 5 Michael Kay 2016-07-10 17:09:08 UTC
I'm inclined now to abandon the idea and do nothing. It has become too complicated.

I tried to specify a function initial-match-item() that returns the current item in the initial match selection, but got bogged down trying to define where it should be available (e.g. not in global variables or stylesheet functions). It's easy enough to achieve the effect with a tunnel parameter if required.
Comment 6 Michael Kay 2016-07-21 16:45:44 UTC
The WG decided that the benefits of these proposed functions did not justify the potential complexity at this stage of the game.