Comment on XQuery issue 26

Comment on XQuery Issue 26: Identity-based equality operator 
(xquery-equality-identity); 
Originator: Algebra Editors; 
Locus: xquery-algebra

Description: Do we need an identity-based equality operator? Please justify
your answer with sample queries. Note that XPath gets along without it.
- - -

I think that an identity-based equality operator IS useful, and that
some operator with an identity-based semantics (like INTERSECT) is 
necessary for some queries.  For example, "Locate <crossref> elements 
that refer to their own ancestor elements":

	FOR $c IN //crossref
	WHERE SOME $a IN $c/ancestor::* SATISFIES
		$a == $c/@refid->*
	RETURN $c

Using value-based equality operator (that is, $a = $c/@refid->*) above would 
select <crossref> elements that refer to a node whose textual value 
happens to be similar to the content of some ancestor of the <crossref>
element.
The above query could be alternatively expressed using
INTERSECT, whose semantics is built on identity-based equality:

	FOR $c IN //crossref
	WHERE NOT empty($c/ancestor::* INTERSECT $c/@refid->*)
	RETURN $c

XPath does not have object identity for nodes, but XSLT has introduced a
work-around function called generate-id() for comparing nodes by unique
string identifiers. Thus it is possible, for example, to simulate XQuery
sample query Q16

	<critical_sequence>
                 LET $p := //procedure[1]
                 FOR $e IN //* AFTER ($p//incision)[1] 
                        BEFORE ($p//incision)[2]
                 RETURN shallow($e)
        </critical_sequence>

by the following XSLT template rule:

<xsl:template match="/">
  <critical_sequence>
    <xsl:variable name="p" select="//procedure[1]" />
    <!-- FOR $e in AFTER ($p//incision)[1]: -->
    <xsl:for-each select="$p//incision[1]/following::*">
    <xsl:variable name="e" select="." />
    <!-- ... and BEFORE ($p//incision)[2]: -->
    <!-- (Note generate-id() for expressing node equality) -->
    <xsl:if test="($p//incision)[2]/preceding::*[
                generate-id(.) = generate-id($e)]">
        <!-- Make a "shallow copy" of $e: -->
        <xsl:element name="{name($e)}">
                <xsl:for-each select="@*">
                  <xsl:copy-of select="." />
                </xsl:for-each>
        </xsl:element>
    </xsl:if>
    </xsl:for-each>
  </critical_sequence>
</xsl:template>
 

Regards, Pekka Kilpeläinen

P.S. Could you moderate the mailing list archive (at
http://lists.w3.org/Archives/Public/www-xml-query-comments/)? Some of its
contents seem to be inappropriate spam.

Pekka Kilpelainen, Univ. of Kuopio, Dept. of Computer Science & Applied Math
    email: Pekka.Kilpelainen@cs.uku.fi
    phone: +358 17 163761, fax: +358 17 162595
    http://www.cs.uku.fi/~kilpelai/

Received on Thursday, 10 May 2001 09:27:22 UTC