W3C home > Mailing lists > Public > www-xml-query-comments@w3.org > May 2001

Comment on XQuery issue 26

From: Pekka Kilpelainen <kilpelai@masto.uku.fi>
Date: Thu, 10 May 2001 16:26:38 +0300 (EET DST)
To: www-xml-query-comments@w3.org
cc: Pekka Kilpelainen <kilpelai@masto.uku.fi>
Message-ID: <Pine.SOL.4.10.10105101558510.21493-100000@masto.uku.fi>
Comment on XQuery Issue 26: Identity-based equality operator 
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->*

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>
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->*)

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

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

by the following XSLT template rule:

<xsl:template match="/">
    <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="." />

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
Received on Thursday, 10 May 2001 09:27:22 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:21:13 UTC