I don't think this is a typing issue - at least not primarily. It's a misunderstanding of what "intersect" does. The intersect operator (like union and except) works on the basis of node identity, not node value. So two nodes in different documents can never be the same node as far as "intersect" is concerned.
In fact this one is much easier. To test if any of the nodes in doc/a[1]/@id has the same value as a node in $list/c/@id, just write
doc/a[1]/@id = $list/c/@id
The "=" operator returns true if any value in the sequence on the left (after atomization) is equal to any value in the sequence on the right (after atomization).
Incidentally (sales pitch) there's an optimized implementation of this in the schema-aware product, which will make a difference if the lists are large. The reason for this is that the optimized algorithm takes account of schema-derived type information when available: but it should give benefits even when there is no schema. The optimized algorithm uses time proportional to m+n where m and n are the list sizes, and memory proportional to min(m,n), whereas the algorithm in the basic product has performance of m*n except in some special cases.
Michael Kay

From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Cary Millsap
Sent: 02 December 2004 01:53
To: saxon-help@lists.sourceforge.net
Subject: [saxon] type dilemma with "intersect"

I’m having a difficult time implementing “@id is an element of $list/@id” by using the construct exists(element intersect list). I know it’s because of a typing issue. I’m buried in Ch9 of the XPath 2.0 book, but I’m stuck. Can you please show me how to nudge the test below into rendering a ‘true’ verdict? Thank you…



<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"





exclude-result-prefixes="xsl xs fn xdt"


       <xsl:variable name="list" as="element()*">

              <e id="1">

                     <c id="3"/>

                     <c id="177"/>


              <e id="2">

                     <c id="149"/>

                     <c id="209"/>

                     <c id="181"/>



       <xsl:template match="/">


                     @id='<xsl:value-of select="/doc/a[1]/@id"/>'

                     $list='<xsl:copy-of select="$list/c"/>'

                     verdict='<xsl:value-of select="exists(/doc/a[1]/@id intersect $list/c/@id)"/>'








<?xml version="1.0" encoding="UTF-8"?>


       <a id="177"/>




Cary Millsap
Hotsos Enterprises, Ltd.
Nullius in verba

Upcoming events:
- Performance Diagnosis 101: 1/4
- SQL Optimization 101: 12/13
- Hotsos Symposium 2005: March 6–10
- Visit www.hotsos.com for schedule details...