<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>25173</bug_id>
          
          <creation_ts>2014-03-27 13:11:50 +0000</creation_ts>
          <short_desc>Test whether a streaming document is available through fn:streaming-document-available()</short_desc>
          <delta_ts>2014-05-23 16:33:51 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XSLT 3.0</component>
          <version>Last Call drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>25174</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Abel Braaksma">abel.braaksma</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>102999</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-03-27 13:11:50 +0000</bug_when>
    <thetext>During the telcon of 13 March 2014, during the discussion about xsl:try and streaming, one suggestion that was made in addition to solving the xsl:try buffering issue, was to be able to query whether a streaming document is available or not.

If we decide to introduce such a function, it can never be a stable function, because streaming documents are not stable upon multiple invocations. However, we can define such a function such that it must attempt to read up to the start of the root note and buffer this for a next invocation of the same URI.

Example:

&lt;xsl:stream href=&quot;{
    if(streaming-document-available($x))
    then $x
    else $y}&quot;&gt;
    ....
&lt;/xsl:stream&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103001</commentid>
    <comment_count>1</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-03-27 13:13:47 +0000</bug_when>
    <thetext>Related: bug 25174.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106056</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-05-15 17:39:15 +0000</bug_when>
    <thetext>During the telcon of 15 May 2014 this bugreport was discussed and the WG requested what semantics the new function should have.

I propose to have it have the same semantics we currently use for reading a streamed document: we currently say that a streamed document must buffer the part up until the root element, and that the DTD, PI&apos;s and comments prior to the root element must be buffered.

I think it makes sense to define it in terms of existing functionality, similarly to the way the XPath function fn:doc-available is defined:

Summary
The function returns true if a streaming document is available.

Signature
fn:streaming-document-available($uri as xs:string?) as xs:boolean

Properties
This function is [non-deterministic], [context-dependent] and [focus-independent], it depends on the static base uri.

Rules
If $uri is the empty sequence, this function returns false.

If the following construct returns true, this function returns true:
&lt;xsl:stream href=&quot;{$arg}&quot;&gt;
   &lt;xsl:value-of select=&quot;has-children(root())&quot; /&gt;
&lt;/xsl:stream&gt;

Error conditions (should we raise FODC0005 if the uri is not well-formed?)

Otherwise, this function returns false.

Notes
If this function returns true, implementers are encouraged to buffer the result of reading up until the root element so that an &lt;xsl:stream&gt; instruction with the same URI will succeed, even in scenario&apos;s where reading a streaming document is forward-only. However, this behavior is not guaranteed for the same reasons multiple invocations of &lt;xsl:stream&gt; on the same URI are not guaranteed deterministic.

This means in practice that this function returns a positive hint that a document is or is not available, but subsequent invocations using &lt;xsl:stream&gt; with the same URI may still fail.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106136</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-05-16 07:25:38 +0000</bug_when>
    <thetext>OK in principle, but I think my preference would be

(a) name the function stream-available()

(b) define it along the following lines: the function returns true if and only if all the following conditions are satisfied:

* The URI is valid, 
* a resource with this URI can be retrieved
* the initial bytes of the resource can be read and decoded as text according to the rules used by an XML processor
* the resulting sequence of characters starts with a string that matches the grammar:

prolog (EmptyElemTag | STag )

as defined in the XML Recommendation

* no implementation-dependent errors, such as would cause the xsl:stream instruction to fail, are detected during the process of opening and parsing the initial content of the stream</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106637</commentid>
    <comment_count>4</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-05-22 11:28:16 +0000</bug_when>
    <thetext>I just checked the XML grammar to be sure I understand it correctly:

Prolog:       xml decl and/or dtd and/or SI/comment/whitespace
STag:         start tag of element
EmptyElemTag: empty element tag

so I think this is the same as matching has-children(root()), except explained in XML grammar and without the potential confusion about consuming the input to process the xpath instruction.

I am unsure about your last paragraph, what implementation dependent errors could raise that allow to read to STag but would still throw?

&gt; * The URI is valid, 

while I think this is preferable, do note that it is a deviation from the semantics of fn:doc-available(), which throws here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106676</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-05-22 22:14:55 +0000</bug_when>
    <thetext>The proposal in comment 3 was accepted today.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106722</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-05-23 16:33:51 +0000</bug_when>
    <thetext>Applied to spec.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>