|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

March 29th, 2006, 01:18 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Location: , , Canada.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
intersect operator
Hi,
I have two variables:
======
The first
=======
<xsl:variable name="v_areaBySRCCD">
<WVS:areaBySRCCDCollection>
<xsl:for-each-group select="//WVS:Src" group-by="WVS:srccode">
<WVS:areaGroup>
<xsl:attribute name="srccode" select="WVS:srccode"/>
<xsl:for-each-group select="current-group()" group-by="WVS:areaCode">
<WVS:areaCode>
<xsl:value-of select="current-grouping-key()"/>
</WVS:areaCode>
</xsl:for-each-group>
</WVS:areaGroup>
</xsl:for-each-group>
</WVS:areaBySRCCDCollection>
</xsl:variable>
========
The second
========
<xsl:variable name="v_sizecoll">
<xsl:variable name="v_coll">
<WVS:Collection>
<xsl:for-each-group select="//WVS:Src" group-by="WVS:areaCode">
<WVS:area>
<WVS:areaCode>
<xsl:value-of select="current-grouping-key()"/>
</WVS:areaCode>
<xsl:variable name="v_cnt" select="sum(current-group()/WVS:count[string(.)!=''])"/>
<WVS:size>
<xsl:if test="$v_cnt > 0">
<xsl:choose>
<xsl:when test="$v_cnt <= 24">1</xsl:when>
<xsl:when test="$v_cnt <= 49">2</xsl:when>
<xsl:when test="$v_cnt <= 99">3</xsl:when>
<xsl:when test="$v_cnt >= 249">4</xsl:when>
</xsl:choose>
</xsl:if>
</WVS:size>
</WVS:area>
</xsl:for-each-group>
</WVS:Collection>
</xsl:variable>
<WVS:sizeCollection>
<xsl:for-each-group select="$v_coll//WVS:area" group-by="WVS:size">
<xsl:sort select="current-grouping-key()"/>
<WVS:sizeGroup>
<xsl:attribute name="size"><xsl:value-of select="current-grouping-key()"/></xsl:attribute>
<xsl:for-each select="current-group()">
<WVS:areaCode>
<xsl:value-of select="WVS:areaCode"/>
</WVS:areaCode>
</xsl:for-each>
</WVS:sizeGroup>
</xsl:for-each-group>
</WVS:sizeCollection>
</xsl:variable>
=======
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?
Thanks,
Francine.
|

March 29th, 2006, 02:02 PM
|
 |
Wrox Author
Points: 12,642, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |