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 3333 - [XQX] stylesheet needs to generate more parenthesis
Summary: [XQX] stylesheet needs to generate more parenthesis
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQueryX 1.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-14 20:39 UTC by Andrew Eisenberg
Modified: 2006-06-29 17:57 UTC (History)
0 users

See Also:


Attachments
XQueryX schema with changes for bug #3333 (40.27 KB, text/plain)
2006-06-29 17:57 UTC, Jim Melton
Details
XQueryX stylesheet with changes for bug #3333 (39.11 KB, text/plain)
2006-06-29 17:57 UTC, Jim Melton
Details

Description Andrew Eisenberg 2006-06-14 20:39:02 UTC
It would seem that the XQueryX stylesheet needs to generate more parenthesis than it does currently.

Consider the following example:

<?xml version="1.0"?>
<xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2005/XQueryX
                                http://www.w3.org/2005/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:addOp>
        <xqx:firstOperand>
          <xqx:integerConstantExpr>
            <xqx:value>7</xqx:value>
          </xqx:integerConstantExpr>
        </xqx:firstOperand>
        <xqx:secondOperand>
          <xqx:flworExpr>
            <xqx:letClause>
              <xqx:letClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>c</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:letExpr>
                  <xqx:integerConstantExpr>
                    <xqx:value>5</xqx:value>
                  </xqx:integerConstantExpr>
                </xqx:letExpr>
              </xqx:letClauseItem>
            </xqx:letClause>
            <xqx:returnClause>
              <xqx:varRef>
                <xqx:name>c</xqx:name>
              </xqx:varRef>
            </xqx:returnClause>
          </xqx:flworExpr>
        </xqx:secondOperand>
      </xqx:addOp>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

This generates the following XQuery, which does not parse:

(7+
 let $c:=5
 return $c
)


Parenthesizing the FLWOR expression would correct this.
Comment 1 Jim Melton 2006-06-15 18:51:11 UTC
Many thanks for your report.  After spending some time thinking about the specific situation that you reported and researching the intended relationships between the XQueryX grammar and the XQuery grammar, it is not completely obvious that your report actually identifies a bug. 

Consider the XQuery syntax that the XQueryX stylesheet generates from your XQueryX document: (7 + let $c:=5 return $c).  As you state, that query is syntactically incorrect.  A syntactically-valid variation is: (7 + (let $c:=5 return $c)), with parentheses surrounding the FLWOR expression "let $c:=5 return $c". 

That suggests that the proper way to express the query in XQueryX is to embed the XQueryX representation of the FLWOR expression in an <xqx:parenthesizedExpr> element.  Naturally, the XQueryX stylesheet would generate the surrounding parentheses, resulting in correct XQuery syntax. 

However, an argument can be made that the XQueryX stylesheet could, without breaking the transformation of any other queries, simply generate parentheses surrounding FLWOR expressions in all situations, as it does for expressions such as sums, differences, products, comparisons, and so forth. 

Before I propose a change to the XML Query Working Group that the stylesheet be modified in this way, I would like a bit more feedback and review. 
Comment 2 David Carlisle 2006-06-21 13:00:45 UTC
> I would like a bit more feedback and review. 

since you ask....

I agree that the styleseet ought to add the parenthesis, although actually I'd go further and remove xqx:parenthesizedExpr from xqueryx, parenthesis are only needed to disambiguate infix operations and there are none in xqueryx.
If the stylesheet going back to xquery is always adding parenthesis based on the element nesting then having an explict nesting element in xqueryx adds nothing.

David
Comment 3 Michael Kay 2006-06-21 13:41:28 UTC
I agree with comment #3. Parentheses in the XQuery syntax perform the same function as start-end tags in the XQueryX syntax. I don't think it serves any useful purpose for XQueryX to retain knowledge of where the parentheses appear in the equivalent XQuery source.
Comment 4 Jim Melton 2006-06-23 08:40:59 UTC
Obviously, the minimal fix is a modification to the stylesheet's template that processes the <xqx:flworExpr/> element -- that fix, of course, is to insert an     <xsl:value-of select="$LPAREN"/> element preceding the template's <xsl:apply-templates/> instrucction, and an <xsl:value-of select="$RPAREN"/> after.  I am making that change regardless. 

A second change, suggested by http://www.w3.org/Bugs/Public/show_bug.cgi?id=3333#c2, would remove the <xqx:parenthesizedExpr/> element entirely.  I am slightly reluctant to do so, in spite of the comment in http://www.w3.org/Bugs/Public/show_bug.cgi?id=3333#c3 that it serves no "useful purpose for XQueryX to retain knowledge of where the parentheses appear...". There is no intent of "retaining knowledge", which implies that such knowledge exists; XQueryX is not intended to be produced as a transformation from an XQuery. The question is whether the author of an XQueryX document wishes to explicitly parenthesize an expression. 

In spite of my reluctance, I yield to my reviewers and have removed the <xqx:parenthesizedExpr/> element. 
Comment 5 Scott Boag 2006-06-24 01:46:25 UTC
(In reply to comment #4)
> ...
> In spite of my reluctance, I yield to my reviewers and have removed the
> <xqx:parenthesizedExpr/> element. 

I am happy enough with this outcome.  My main concern is that the spec should be consistent one way or the other regarding the translation of parenthesizedExpr.  Is it ever useful?
Comment 6 Jim Melton 2006-06-26 20:38:33 UTC
The XML Query endorsed changes to both the XQueryX schema and the XQueryX stylesheet to address this problem.  The change to the stylesheet causes parentheses to be generated to surround generated FLWOR expressions, while the change to the schema removes the ability to use the <xqx:parenthesizedExpr> element.  We do not believe that the <xqx:parenthesizedExpr> element provides any necessary capabilties. 

Since this resolves your request, and you were present when the decision was made, I am marking this bug FIXED and then CLOSED. 
Comment 7 David Carlisle 2006-06-27 10:05:26 UTC
I think that when editing the schema you need to replace
xqx:parenthesizedExpr by xqx:sequenceExpr in the big xsd:choice group defining the filterExpr group rather than just deleting it. (It's not clear from the comments posted so far exactly what the schema change proposed is).

Otherwise you have no way of encoding

a/(1,2,3)

xqx:parenthesizedExpr serves no purpose, as the stylesheet would anyway put () around xqx:sequenceExpr at this position but you need to allow sequenceExpr there first.

David
Comment 8 Jim Melton 2006-06-29 17:55:31 UTC
David, thanks for the reminder.  I've had problems posting the revised schema and stylesheet, but I could have saved you the trouble if I had been able to post them.  Better redundant than incomplete, though!
Comment 9 Jim Melton 2006-06-29 17:57:00 UTC
Created attachment 436 [details]
XQueryX schema with changes for bug #3333
Comment 10 Jim Melton 2006-06-29 17:57:37 UTC
Created attachment 437 [details]
XQueryX stylesheet with changes for bug #3333