- From: <bugzilla@wiggum.w3.org>
- Date: Fri, 28 Aug 2009 01:07:22 +0000
- To: public-qt-comments@w3.org
http://www.w3.org/Bugs/Public/show_bug.cgi?id=7450
Summary: [XPath] 'for' expression example does not produce
expected output
Product: XPath / XQuery / XSLT
Version: Recommendation
Platform: All
URL: http://www.w3.org/TR/2007/REC-xpath20-20070123/#id-for-
expressions
OS/Version: All
Status: NEW
Severity: trivial
Priority: P5
Component: XPath
AssignedTo: jonathan.robie@redhat.com
ReportedBy: zongaro@ca.ibm.com
QAContact: public-qt-comments@w3.org
Some colleagues pointed out a problem in example 'for' 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 "transforms the
input document into a list in which each author's name appears only once,
followed by a list of titles of books written by that author."
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:
<author>Stevens</author>
<author>Stevens</author>
<title>TCP/IP Illustrated</title>
<title>Advanced Programming in the Unix environment</title>
<author>Abiteboul</author>
<title>Data on the Web</title>
<author>Buneman</author>
<title>Data on the Web</title>
<author>Suciu</author>
<title>Data on the Web</title>
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
--
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
Received on Friday, 28 August 2009 01:07:30 UTC