473,434 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

NodeSet Reduction

Hi All,

I have been pulling my hair out with this one for the past three days,
using every combination of XPATH I can think of so even the tinniest
bit of help from anyone would be great.

I have a node set '$sub_set' that contains three <row> elements:

<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
<row>
<field1>value1</field1><field2>value2</field2>
</row>

these have been extracted from:
<condition num="1">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
</condition>
<condition num="2">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
</condition>

I would like to reduce '$sub_set' down to just:
<row>
<field1>value3</field1><field2>value4</field2>
</row>

I will not list all the many XPATH expressions I have tried but this
is the closest I know that SHOULD work.
$current_row = $sub_set[1]
$sub_set[* != $current_row] - but this returns all three all original
nodes!

Does anyone have any ideas?

Bryan
Jul 20 '05 #1
3 1378
br**********@hotmail.com (Bryan Galvin) writes:
I have a node set '$sub_set' that contains three <row> elements:

<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
<row>
<field1>value1</field1><field2>value2</field2>
</row>

these have been extracted from:
<condition num="1">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
</condition>
<condition num="2">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
</condition>

I would like to reduce '$sub_set' down to just:
<row>
<field1>value3</field1><field2>value4</field2>
</row>


I'm not sure what you mean by "reduce '$sub_set' down". Do you just
mean that you want to extract the second node from the node-set?

If so, then what about this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">

<!-- This sets up $sub_set with the three nodes, exactly
as you have it -->
<xsl:variable name="sub_set" select="foo/condition/row"/>

<!-- This extracts the second -->
<xsl:copy-of select="$sub_set[2]"/>

</xsl:template>

</xsl:stylesheet>
NB. I've made your XML properly-formed for this demonstration:

<foo>
<condition num="1">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
</condition>
<condition num="2">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
</condition>
</foo>
If that doesn't answer your question then perhaps you need to state it
more clearly.

Ben

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #2
In article <97**************************@posting.google.com >, Bryan Galvin wrote:
I have been pulling my hair out with this one for the past three days,
using every combination of XPATH I can think of so even the tinniest
bit of help from anyone would be great.

I have a node set '$sub_set' that contains three <row> elements:

<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
<row>
<field1>value1</field1><field2>value2</field2>
</row>

these have been extracted from:
<condition num="1">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
</condition>
<condition num="2">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
</condition>

I would like to reduce '$sub_set' down to just:
<row>
<field1>value3</field1><field2>value4</field2>
</row>

I will not list all the many XPATH expressions I have tried but this
is the closest I know that SHOULD work.
$current_row = $sub_set[1]
$sub_set[* != $current_row] - but this returns all three all original
nodes!

Does anyone have any ideas?


You may want to use

$sub_set[. != $current_row]

The != expression on two nodes sets is true if and only if there is a
node in the first node-set and a node in the second node-set such that
the result of performing the comparison on the string-values of the two
nodes is true.

The string value of $current_row is "\n value1value2\ " (the
concatenated string values of its descendants including the text nodes).

The $sub_set[* != $current_row] expression tests the three elements in
$sub_set named row. For each "row" element it tests whether the string
value of each subelement of the "row" element is not equal to the
string value of $current_row.

For the first "row" element it tests whether "value1" != $current_row
and whether "value2" != $current_row. The first "row" element is in the
resulting node set because both tests are true. A "row" element is in
the resulting node set if any of the tests are true. For similar
reasons the other "row" nodes are in the resulting node set too.

The $sub_set[. != $current_row] expression also tests the three elements
in $sub_set named row. For each "row" element it tests whether the
string value of the "row" element is not equal to the string value of
$current_row.

For the first "row" element it tests whether "\n value1value2\n "
!= $current_row. The first "row" element is not in the resulting node
set because the test is false. The second "row" node is in the resulting
node set because its test is true ("\n value3value4\n " !=
$current_row. The third "row" node is not in the resulting node set
because "\n value1value2\n " != $current_row.
Jul 20 '05 #3
A. Bolmarcich,

Thanks for that. It solved the problem for me. The explanation was
useful because it helped clear-up my understanding of the W3C.org
specification on node set comparisons.

Bryan

ag*****@earl-grey.cloud9.net (A. Bolmarcich) wrote in message news:<slrnccea0n.1hm4.ag*****@earl-grey.cloud9.net>...
In article <97**************************@posting.google.com >, Bryan Galvin wrote:
I have been pulling my hair out with this one for the past three days,
using every combination of XPATH I can think of so even the tinniest
bit of help from anyone would be great.

I have a node set '$sub_set' that contains three <row> elements:

<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
<row>
<field1>value1</field1><field2>value2</field2>
</row>

these have been extracted from:
<condition num="1">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
<row>
<field1>value3</field1><field2>value4</field2>
</row>
</condition>
<condition num="2">
<row>
<field1>value1</field1><field2>value2</field2>
</row>
</condition>

I would like to reduce '$sub_set' down to just:
<row>
<field1>value3</field1><field2>value4</field2>
</row>

I will not list all the many XPATH expressions I have tried but this
is the closest I know that SHOULD work.
$current_row = $sub_set[1]
$sub_set[* != $current_row] - but this returns all three all original
nodes!

Does anyone have any ideas?


You may want to use

$sub_set[. != $current_row]

The != expression on two nodes sets is true if and only if there is a
node in the first node-set and a node in the second node-set such that
the result of performing the comparison on the string-values of the two
nodes is true.

The string value of $current_row is "\n value1value2\ " (the
concatenated string values of its descendants including the text nodes).

The $sub_set[* != $current_row] expression tests the three elements in
$sub_set named row. For each "row" element it tests whether the string
value of each subelement of the "row" element is not equal to the
string value of $current_row.

For the first "row" element it tests whether "value1" != $current_row
and whether "value2" != $current_row. The first "row" element is in the
resulting node set because both tests are true. A "row" element is in
the resulting node set if any of the tests are true. For similar
reasons the other "row" nodes are in the resulting node set too.

The $sub_set[. != $current_row] expression also tests the three elements
in $sub_set named row. For each "row" element it tests whether the
string value of the "row" element is not equal to the string value of
$current_row.

For the first "row" element it tests whether "\n value1value2\n "
!= $current_row. The first "row" element is not in the resulting node
set because the test is false. The second "row" node is in the resulting
node set because its test is true ("\n value3value4\n " !=
$current_row. The third "row" node is not in the resulting node set
because "\n value1value2\n " != $current_row.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jason | last post by:
Hi - this post overlaps with another post (Tom K was helping) but has a differnt slant and explanation which I feel warrants a new post..... If one has a series of price reduction fields (3) and...
4
by: Brad | last post by:
Help, I have a really complicated XPATH request I can't wrap my head around I have an XML nodeset like this: <a> <a1 attr="key">Use</a1> <a1 attr="val">Value1</a2> </a> <a> <a1...
2
by: Bryan Galvin | last post by:
Hi all, I posted a message on this topic before, but now I have a request for help. Previously "A. Bolmarcich" answered this query for me, but the problem has changed slightly... I have two...
4
by: David Blickstein | last post by:
I have an application where I have a shared "method" of selecting a nodeset. The method currently is duplicated everywhere it is needed but I'd like that code to be shared. The method also...
1
by: Damien Goutte-Gattat | last post by:
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called...
2
by: amit L via DotNetMonster.com | last post by:
hi all. i've been trying to pass a nodelist (!=nodeset??) from my c# application to some xsl transform to use. the xsl code is as follows: <xsl:stylesheet version="1.0"...
0
by: KathyB | last post by:
Hi, Using the following in an asp.net procedure. I get the error "The expression passed to this method should result in a NodeSet". Dim xDoc As New Document() The line causing the error is:...
0
by: Hoi-Polloi | last post by:
Hi all I want to use an xpath query to get a set of xmlNodePtr , but I don't want to keep the xmlXPathObject around. See the function below. I want to: * make xpath query and get an...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
14
by: eric.goforth | last post by:
Hello, Is there any way to directly access an element in a nodeset? For example, if working with: <blahs rec_count="16"> <blah> <yada>abc</yada> </blah>
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.