<?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>29604</bug_id>
          
          <creation_ts>2016-04-30 10:20:23 +0000</creation_ts>
          <short_desc>[XSLT30] Request for clarification of statement in section https://www.w3.org/TR/xslt-30/#stream-examples</short_desc>
          <delta_ts>2016-06-02 19:31:38 +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>Candidate Recommendation</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>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Martin Honnen">martin.honnen</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>126309</commentid>
    <comment_count>0</comment_count>
    <who name="Martin Honnen">martin.honnen</who>
    <bug_when>2016-04-30 10:20:23 +0000</bug_when>
    <thetext>The section https://www.w3.org/TR/xslt-30/#stream-examples shows two uses of xsl:stream with the accumulator functions count and max and the examples work fine for me with Saxon 9.7. However that sections ends with the statement &quot;To compute both the count and the maximum value in a single pass over the input, it is possible to use two variables.&quot;. I would like to see an example that does that as it appears the naive approach of 

	&lt;xsl:template name=&quot;xsl:initial-template&quot;&gt;
		&lt;xsl:stream href=&quot;transactions.xml&quot;&gt;
			&lt;xsl:variable name=&quot;count&quot; select=&quot;count(transactions/transaction)&quot;/&gt;
			&lt;xsl:variable name=&quot;max&quot; select=&quot;max(transactions/transaction/xs:decimal(@value))&quot;/&gt;
			&lt;count&gt;
				&lt;xsl:value-of select=&quot;$count&quot;/&gt;
			&lt;/count&gt;
			&lt;maxValue&gt;
				&lt;xsl:value-of select=&quot;$max&quot;/&gt;
			&lt;/maxValue&gt;
		&lt;/xsl:stream&gt;
	&lt;/xsl:template&gt;

does not work with Saxon, it complains 

Static error in xsl:stream/@href on line 10 column 41 of test201604300104.xsl:
  XTSE3430: The body of the xsl:stream instruction is not streamable
  *  There is more than one consuming operand: {count(...)} on line 11, and {let $max :=
  ...} on line 10

What I got to work is an example using a map

	&lt;xsl:template name=&quot;xsl:initial-template&quot;&gt;
		&lt;xsl:stream href=&quot;transactions.xml&quot;&gt;
			&lt;xsl:variable name=&quot;map&quot; as=&quot;map(xs:string, xs:decimal)&quot;
				select=&quot;map{&apos;count&apos;: count(transactions/transaction),
				            &apos;max&apos;: max(transactions/transaction/xs:decimal(@value))}&quot;/&gt;
			&lt;count&gt;
				&lt;xsl:value-of select=&quot;$map(&apos;count&apos;)&quot;/&gt;
			&lt;/count&gt;
			&lt;maxValue&gt;
				&lt;xsl:value-of select=&quot;$map(&apos;max&apos;)&quot;/&gt;
			&lt;/maxValue&gt;
		&lt;/xsl:stream&gt;
	&lt;/xsl:template&gt;
	
but that is no a use of two variables. 

So I hope the comment &quot;To compute both the count and the maximum value in a single pass over the input, it is possible to use two variables.&quot; could be accompanied by an example that shows how to do that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126419</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-12 10:15:57 +0000</bug_when>
    <thetext>I really have no idea what we were thinking of when we wrote the sentence:

&quot;To compute both the count and the maximum value in a single pass over the input, it is possible to use two variables.&quot;

Perhaps the spec was different when we wrote that, and we failed to notice the effect of a change.

In fact the way I would recommend computing multiple aggregates is to use a map:

&lt;xsl:template name=&quot;xsl:initial-template&quot; expand-text=&quot;yes&quot;&gt;
  &lt;xsl:stream href=&quot;transactions.xml&quot;&gt;
    &lt;xsl:variable name=&quot;aggregates&quot; 
      select=&quot;map{&apos;count&apos;: count(transactions/transaction),
                  &apos;maxValue&apos;: &quot;max(transactions/transaction/xs:decimal(@value))}&quot;/&gt;
    &lt;count&gt;{$count}&lt;/count&gt;
    &lt;maxValue&gt;{$max}&lt;/maxValue&gt;
  &lt;/xsl:stream&gt;
&lt;/xsl:template&gt;

I haven&apos;t tested this under Saxon but it ought to work, and I think it would be a good idea to add the example to the spec.

(We decided to special-case map constructors so that multiple consuming operands are allowed: they therefore become a convenient way to capture multiple results during a single scan of the input. This can also be achieved using xsl:fork or using accumulators, but those mechanisms are much more complex.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126420</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-12 10:18:04 +0000</bug_when>
    <thetext>Whoops, I wish that Bugzilla allowed you to edit your submissions! Here&apos;s an improvement:

&lt;xsl:template name=&quot;xsl:initial-template&quot; expand-text=&quot;yes&quot;&gt;
  &lt;xsl:stream href=&quot;transactions.xml&quot;&gt;
    &lt;xsl:variable name=&quot;aggregates&quot; 
      select=&quot;map{&apos;count&apos;: count(transactions/transaction),
                  &apos;maxValue&apos;: &quot;max(transactions/transaction/xs:decimal(@value))}&quot;/&gt;
    &lt;count&gt;{$aggregates?count}&lt;/count&gt;
    &lt;maxValue&gt;{$aggregates?maxValue}&lt;/maxValue&gt;
  &lt;/xsl:stream&gt;
&lt;/xsl:template&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126586</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-26 16:21:04 +0000</bug_when>
    <thetext>The editor has an action to improve the examples to show how to solve this:

ACTION  2016-05-12-002: Michael Kay to work out a map, fork and accumulator examples as in comment 2 of bug 29604, to be added to the spec, and to remove XP31 specific syntax</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126600</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-27 09:50:40 +0000</bug_when>
    <thetext>I have removed the offending sentence, and have included an example along the lines of comment #2 showing how to solve the problem with maps. I also mention the possibility of using xsl:fork or xsl:accumulator to solve the problem; but I decided not to include fully-worked examples of these approaches because (a) it&apos;s not the best way of solveing the problem, and (b) it goes off at a tangent in terms of the concepts we are trying to introduce at this point in the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126648</commentid>
    <comment_count>5</comment_count>
    <who name="Martin Honnen">martin.honnen</who>
    <bug_when>2016-06-02 14:11:59 +0000</bug_when>
    <thetext>The example in https://www.w3.org/XML/Group/qtspecs/specifications/xslt-30/html/#stream-examples has a slight syntax error as the key name of the second map entry is written as 
  &apos;max&quot;:
so the second quote is a mismatch, it should be
  &apos;max&apos;:

Probably more a cosmetic problem but as it one day goes into an official recommendation it might be worth fixing it so that people reading it and new to both streaming and maps don&apos;t stumble over the syntax error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126653</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-02 19:31:38 +0000</bug_when>
    <thetext>Thanks, I have fixed the typo.

The WG reviewed and accepted the changes.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>