[Bug 2523] xqx: pathExpr and stepExpr

http://www.w3.org/Bugs/Public/show_bug.cgi?id=2523





------- Additional Comments From davidc@nag.co.uk  2006-01-07 23:09 -------
Thanks for your feedback.

Clearly schema changes would require some changes to the stylesheet,
as for example the template for pathExpr currently looks for argExpr
children which would no longer there.

The notes below assume some educated (or more exactly, uneducated)
guesses about the changes you had in mind, as of course without the
stylesheet the meaning of the xqueryx that validates the new schema is
unspecified.

With that health warning over, I don't see how you intend to denote a
non-relative xpath such as /a/b as just allowing stepExpr in pathexpr
gives no place to record an initial rootExpr. Also the XQuery BNF for
pathExpr (ignoring the parts dealing with // which are not relevant
here) allows a choice (/ followed by 0-or-more steps) or (1-more-steps).

The position of rootExpr in the schema was already a little murky, see
for example bug #2525.

If I may make an explicit suggestion I would alter the CR schema as
follows


1)
Delete rootExpr as a top level element, so it can only appear in a
pathExpr

<!--
  <xsd:complexType name="rootExpr">
    <xsd:complexContent>
      <xsd:extension base="expr"/>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:element name="rootExpr" type="rootExpr" substitutionGroup="expr"/>
-->

2) define stepExpr as you suggest in your comment in this bug:

  <xsd:element name="stepExpr">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice>
          <xsd:sequence>
            <xsd:element ref="xpathAxis"/>
            <xsd:choice>
              <xsd:element ref="kindTest"/>
              <xsd:element ref="nameTest"/>
              <xsd:element ref="Wildcard"/>
             </xsd:choice>
          </xsd:sequence>
          <xsd:element name="filterExpr">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:group ref="filterExpr"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
        <xsd:element name="predicates" type="exprList" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

2) define pathExpr so it matches the Query BNF of (/ step* ) | (step+)

  <xsd:complexType name="pathExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
	<xsd:choice>
	  <xsd:sequence>
	    <xsd:element name="rootExpr" type="emptyContent"/>
	    <xsd:element ref="stepExpr" minOccurs="0" maxOccurs="unbounded"/>
	  </xsd:sequence>
	  <xsd:element ref="stepExpr" maxOccurs="unbounded"/>
	</xsd:choice>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  
  <xsd:element name="pathExpr" type="pathExpr" substitutionGroup="expr"/>


and alter the stylesheet to match:

3) define the template for pathExpr so that it processes rootExpr and
stepExpr rather than argExpr, predicates and stepExpr

  <xsl:template match="xqx:pathExpr">
    <xsl:apply-templates select="xqx:rootExpr|xqx:stepExpr"/>
  </xsl:template>



4) Define the template for stepExpr so that it only looks for other
stepExpr not any element before inserting a / (so you don't get a /
after a leading /, which (now) comes from processing rootExpr.

 <xsl:template match="xqx:stepExpr">
    <xsl:if test="preceding-sibling::xqx:stepExpr">
      <xsl:value-of select="$SLASH"/>
    </xsl:if>
    <xsl:apply-templates select="*"/>
  </xsl:template>


That's it...

Er I even tested this a bit.

Starting with the XqueryX below intended to represent the same thing
as the Xquery

(/,/a/b,a/b,ancestor::x[1],(ancestor::x)[1])

I claim the xqueryx is valid to the schema as modified above, and
produces

(/,
/child::a/child::b,
child::a/child::b,
ancestor::x[1],
(ancestor::x)[1])

if processed with the stylesheet as modified above, and that this is
probably the desired result:-)

<xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:sequenceExpr>
	<xqx:pathExpr>
	  <xqx:rootExpr/>
	</xqx:pathExpr>
	<xqx:pathExpr>
	  <xqx:rootExpr/>
	  <xqx:stepExpr>
	    <xqx:xpathAxis>child</xqx:xpathAxis>
	    <xqx:nameTest>a</xqx:nameTest>
	  </xqx:stepExpr>
	  <xqx:stepExpr>
	    <xqx:xpathAxis>child</xqx:xpathAxis>
	    <xqx:nameTest>b</xqx:nameTest>
	  </xqx:stepExpr>
	</xqx:pathExpr>
	<xqx:pathExpr>
	  <xqx:stepExpr>
	    <xqx:xpathAxis>child</xqx:xpathAxis>
	    <xqx:nameTest>a</xqx:nameTest>
	  </xqx:stepExpr>
	  <xqx:stepExpr>
	    <xqx:xpathAxis>child</xqx:xpathAxis>
	    <xqx:nameTest>b</xqx:nameTest>
	  </xqx:stepExpr>
	</xqx:pathExpr>
	<xqx:pathExpr>
	  <xqx:stepExpr>
	    <xqx:xpathAxis>ancestor</xqx:xpathAxis>
	    <xqx:nameTest>x</xqx:nameTest>
	    <xqx:predicates>
	      <xqx:integerConstantExpr>
		<xqx:value>1</xqx:value>
	      </xqx:integerConstantExpr>
	    </xqx:predicates>
	  </xqx:stepExpr>
	</xqx:pathExpr>
	<xqx:pathExpr>
	  <xqx:stepExpr>
	    <xqx:filterExpr>
	      <xqx:parenthesizedExpr>
		<xqx:pathExpr>
		  <xqx:stepExpr>
		    <xqx:xpathAxis>ancestor</xqx:xpathAxis>
		    <xqx:nameTest>x</xqx:nameTest>
		  </xqx:stepExpr>
		</xqx:pathExpr>
	      </xqx:parenthesizedExpr>
	    </xqx:filterExpr>
	    <xqx:predicates>
	      <xqx:integerConstantExpr>
		<xqx:value>1</xqx:value>
	      </xqx:integerConstantExpr>
	    </xqx:predicates>
	  </xqx:stepExpr>
	</xqx:pathExpr>
      </xqx:sequenceExpr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

Received on Saturday, 7 January 2006 23:09:55 UTC