[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problems selecting the right nodes.

Subject: Re: Problems selecting the right nodes.
From: Adam van den Hoven <list@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 26 Sep 2003 10:05:07 -0700
xsl subset nodes
Thanks everyone for your help.

It seems that I made something unclear. The nodeset that I'm working with is a subset of my data. This adds a significant level of complexity to the problem. Micheal's suggestion of testing count(key(...)) != count(/*/branch) is great except that key returns too many elements since it takes in the whole document, not my subset.

This makes things more difficult. What I have, so far comes from Steven's suggestion (You'll notice that I added the region tag to demostrate the filtering):

<xsl:template match="/">
<xsl:variable name="filtered-branches" select="branches/branch[region/@id ='region5']"/>
<xsl:variable name="unique-services" select="/branches/branch/service[generate-id(.) = generate-id(key('service',@id))]"/>
<xsl:variable name="filtered-unique-services" select="$unique-services[@id = $filtered-branches/service/@id]"/>
<xsl:variable name="rtf-selectable-services">
<xsl:apply-templates select="$filtered-unique-services">
<xsl:with-param name="branches" select="$filtered-branches"/>
</xsl:apply-templates>
</xsl:variable>
<!-- I had trouble where xalan:nodeset($rtf-selectable-services) returned only 1 node so I did this just to make sure I got the elements I wanted -->
<xsl:variable name="selectable-services" select="xalan:nodeset($rtf-selectable-services)/descendant-or-self::service"/>
<!-- ok do real work, now, counting is a good substitute -->
<xsl:value-of select="count($selectable-services)"/>
</xsl:template>
<xsl:template match="service" mode="getselectable">
<xsl:param name="branches"/>
<xsl:if test="$branches[not(service/@id = current()/@href)]">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>



So this works. However, in my real problem, which this is a simplification of, I have two elements which I need to do this for. So I am beginning to wonder if its better to do this twice, which is a little messy already, or to take my filtered branches, call nodeset on those and then take Michael's suggestion. However, then I have the problem of changing the current node to be my filtered nodeset and keeping that variable around


Any more thoughts?

Adam


Michael Kay wrote:


But this is an O(n^2) solution and doesn't remove the duplicates...

Michael Kay



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Kienle, Steven C [PGRD/0200]
Sent: 25 September 2003 18:01
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: Problems selecting the right nodes.




I'm not sure if this will fit the bill, but it does return the correct results with your sample below.

<xsl:template match="service">
   <xsl:if test="/root/branch[not(service/@id = current()/@id)]">
       <xsl:value-of select="@id" />
   </xsl:if>
</xsl:template>

Basically, this matches the service nodes and only executes the value-of when the exists a branch which does not have a service with the same @id as the current service. Because it is processing nodes, it possible that you could have some duplication, which you may not want. You might be able to use this as a starting point.

Steve

-----Original Message-----
From: Adam van den Hoven [mailto:list@xxxxxxxxxxxxxxxxxxx]

I have a nodeset or arbitrary length that contains a set of tags which look something like:

<branch id="br1">
  <service id="service1" />
  <service id="service2" />
  <service id="service3" />
</branch>
<branch id="br2">
   <service id="service1" />
   <service id="service4" />
</branch>

Now what I want is a nodeset that contains (uniquely) all the services that do not occur in all the branches. In this case I want service 2, 3 and 4 but not 1


This communication is intended solely for the use of the addressee and may contain information that is legally privileged, confidential or exempt from disclosure. If you are not the intended recipient, please note that any dissemination, distribution, or copying of this communication is strictly prohibited. Anyone who receives this message in error should notify the sender immediately and delete it from his or her computer.



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list






XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list








XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.