<?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>7450</bug_id>
          
          <creation_ts>2009-08-28 01:07:21 +0000</creation_ts>
          <short_desc>[XPath] &apos;for&apos; expression example does not produce expected output</short_desc>
          <delta_ts>2010-02-17 22:56:28 +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>XPath 2.0</component>
          <version>Recommendation</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.w3.org/TR/2007/REC-xpath20-20070123/#id-for-expressions</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P5</priority>
          <bug_severity>trivial</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Henry Zongaro">zongaro</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</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>26727</commentid>
    <comment_count>0</comment_count>
    <who name="Henry Zongaro">zongaro</who>
    <bug_when>2009-08-28 01:07:21 +0000</bug_when>
    <thetext>Some colleagues pointed out a problem in example &apos;for&apos; expression that appears in the second box in section 3.7 of XPath 2.0.[1]

    for $a in fn:distinct-values(book/author)
    return (book/author[. = $a][1], book[author = $a]/title)

The paragraph that appears before the example indicates that it &quot;transforms the input document into a list in which each author&apos;s name appears only once, followed by a list of titles of books written by that author.&quot;

However, the expression before the comma operator actually selects, for each book element that has one or more author elements that match $a, the first such author element for that book.  So one author element will appear for each book written by that author.  With the given input, the output will be:

&lt;author&gt;Stevens&lt;/author&gt;
&lt;author&gt;Stevens&lt;/author&gt;
&lt;title&gt;TCP/IP Illustrated&lt;/title&gt;
&lt;title&gt;Advanced Programming in the Unix environment&lt;/title&gt;
&lt;author&gt;Abiteboul&lt;/author&gt;
&lt;title&gt;Data on the Web&lt;/title&gt;
&lt;author&gt;Buneman&lt;/author&gt;
&lt;title&gt;Data on the Web&lt;/title&gt;
&lt;author&gt;Suciu&lt;/author&gt;
&lt;title&gt;Data on the Web&lt;/title&gt;

The following was probably intended:

    for $a in fn:distinct-values(book/author)
    return ((book/author[. = $a])[1], book[author = $a]/title)

The corresponding example in XQuery 1.0 was written differently, and does not have the same problem.

[1] http://www.w3.org/TR/2007/REC-xpath20-20070123/#id-for-expressions</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31743</commentid>
    <comment_count>1</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-02-11 00:31:26 +0000</bug_when>
    <thetext>I am fixing this for future versions of XPath.

</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>