Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 29th, 2006, 01:18 PM
Registered User
Join Date: Mar 2006
Location: , , Canada.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default intersect operator

I have two variables:
The first
<xsl:variable name="v_areaBySRCCD">
        <xsl:for-each-group select="//WVS:Src" group-by="WVS:srccode">
                <xsl:attribute name="srccode" select="WVS:srccode"/>
                <xsl:for-each-group select="current-group()" group-by="WVS:areaCode">
                        <xsl:value-of select="current-grouping-key()"/>
The second
<xsl:variable name="v_sizecoll">
    <xsl:variable name="v_coll">
            <xsl:for-each-group select="//WVS:Src" group-by="WVS:areaCode">
                    <xsl:value-of select="current-grouping-key()"/>
                    <xsl:variable name="v_cnt" select="sum(current-group()/WVS:count[string(.)!=''])"/>
                        <xsl:if test="$v_cnt &gt; 0">
                              <xsl:when test="$v_cnt &lt;= 24">1</xsl:when>
              <xsl:when test="$v_cnt &lt;= 49">2</xsl:when>
    <xsl:when test="$v_cnt &lt;= 99">3</xsl:when>
    <xsl:when test="$v_cnt &gt;= 249">4</xsl:when>
            <xsl:for-each-group select="$v_coll//WVS:area" group-by="WVS:size">
                <xsl:sort select="current-grouping-key()"/>
                    <xsl:attribute name="size"><xsl:value-of select="current-grouping-key()"/></xsl:attribute>
                    <xsl:for-each select="current-group()">
                            <xsl:value-of select="WVS:areaCode"/>
The first variable returns a node-set but the second one does not. I, therefore, am not able to apply the [u]intersect</u> operator to get <WVS:areaCode/>'s that result from their intersection. Do you have any idea why the second variable is not a node-set? Declaring it as node()* using the 'as' attribute does not work either.
Right now, I can generate a sequence of intersecting <WVS:areaCode/>'s by looping through each variable as a sequence but it is very slow when processing half a million records.
<xsl:variable name="areacodes" select="for $i in $areaBySRCCD//WVS:areaCode, $j in $sizecoll//WVS:areaCode return if ($i eq $j) then $i else ''"/>

Any suggestions?


Old March 29th, 2006, 02:02 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Both variables are "node-sets" (node sequences in XSLT 2.0 parlance). But each of them holds a single node, and they hold different nodes, so the intersection will be empty. Perhaps you are making the mistake of thinking that intersect compares nodes for equality rather than identity.

I think that what you are doing is probably a join rather than an intersection: the usual way of speeding this up in XSLT is to use keys.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use like operator thillaiarasu SQL Server 2000 4 April 23rd, 2010 09:47 AM
having problem with Between operator anantdev SQL Language 1 May 26th, 2008 08:14 AM
=== operator in c# surendraparashar C# 2005 8 November 8th, 2007 05:14 AM
Invalid operator for data type. Operator equals di Pusstiu SQL Server 2000 2 August 10th, 2007 04:51 AM
variable as operator... wrofox Classic ASP Databases 2 March 2nd, 2005 03:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.