473,651 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPATH: Selecting child nodes wich are NOT equal to

Hello,

suppose i have a dom like this:

<a>
- <b>
- <b>
- <d>
- </b>
- <c>
- <e/>
- </c>
- <f/>
</a>
now to select al f child nodes of a, is : a[f]

but how do i select all child nodes of a that are not equeal to f??

a[!f] does not work.

How do i do that??!?!?!
Jul 20 '05 #1
9 16639
Tjerk Wolterink wrote:
Hello,

suppose i have a dom like this:

<a>
- <b>
- <b>
- <d>
- </b>
- <c>
- <e/>
- </c>
- <f/>
</a>
now to select al f child nodes of a, is : a[f]

but how do i select all child nodes of a that are not equeal to f??

a[!f] does not work.

How do i do that??!?!?!


is it this?

a[child:* != f]
Jul 20 '05 #2
Hi,
suppose i have a dom like this:

<a>
- <b>
- <b>
- <d>
- </b>
- <c>
- <e/>
- </c>
- <f/>
</a>
now to select al f child nodes of a, is : a[f]
That's not correct actually. It should be a/f
but how do i select all child nodes of a that are not equeal to f??

a[!f] does not work.

How do i do that??!?!?!


is it this?

a[child:* != f]

No, what you need is:

a/*[not(self::f)]
or
a/*[local-name()!='f']

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3
wait ii'm saying it al wrong,

suppose i have the folowwing xml:

<a>
<d>ereR</d>
Hey <b>i <c><d>a</d>m<c></b>
</q>Henk<q>
<d>erer</d>
</a>
Now i with xsl:

<xsl:template match="a">
<xsl:value-of select="[XPATH]"/>
</xsl:template>

Where [XPATH] should select the text of a without the <d></d> elements
of the contents of the a element
So it should select:
Hey <b>i <c>m<c></b>
</q>Henk<q>

because that is all in a without <d> elements

How do i do that?

Jul 20 '05 #4
> <a>
<d>ereR</d>
Hey <b>i <c><d>a</d>m</c></b>
<q>Henk</q>
<d>erer</d>
</a>
Now i with xsl:

<xsl:template match="a">
<xsl:value-of select="[XPATH]"/>
</xsl:template>

Where [XPATH] should select the text of a without the <d></d> elements
of the contents of the a element
So it should select:
Hey <b>i <c>m</c></b>
<q>Henk</q>
How do i do that?

Hi,

I don't think it can be put in one Xpath expression. (I could be mistaking).

To get the sample output you gave, you'd have to do something like this:

<xsl:template match="a">
<xsl:apply-templates select="node()[not(self::d)]" mode="ignore-d"/>
</xsl:template>

<xsl:template match="*" mode="ignore-d">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::d)]" mode="ignore-d"/>
</xsl:copy>
</xsl:template>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #5
that did not help,
let me give an example:

<page:link page="pages/medewerker.page .xml">
<page:var>
<page:name>id </page:name <page:value>val ue</page:value>
</page:var>
<page:var>
<page:name>id 2</page:name <page:value>val ue2</page:value>
</page:var>
Bla <center>Bla <b>Bla</b></center>
</page:link>
This should be transformed to:

<a href="/index.php?page= pages/medewerker.page .xml&id=value&i d2=value2">
Bla <center>Bla <b>Bla</b></center>
</a>

Well i dont know how to do that,
now i have the following xsl-template:

<!--
! Matches a link to another page.xml file
!-->
<xsl:template match="page:lin k">
<a>
<xsl:attribut e name="href">
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
<xsl:value-of select="./text()./*[not(self::page: var)]"/> -->
</a>
</xsl:template>

How should i do it?
Jul 20 '05 #6
> that did not help,
let me give an example:

<page:link page="pages/medewerker.page .xml">
<page:var>
<page:name>id </page:name <page:value>val ue</page:value>
</page:var>
<page:var>
<page:name>id 2</page:name <page:value>val ue2</page:value>
</page:var>
Bla <center>Bla <b>Bla</b></center>
</page:link>
This should be transformed to:

<a href="/index.php?page= pages/medewerker.page .xml&id=value&i d2=value2">
Bla <center>Bla <b>Bla</b></center>
</a>


It works for me with these templates:

############### ############### #############
<xsl:template match="page:lin k">
<a>
<xsl:attribut e name="href">
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</a>
</xsl:template>

<xsl:template match="*" mode="ignore">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</xsl:copy>
</xsl:template>

############### ############### #############
But if the xml structure really is a simple as in this example (no deeper nested elements that should be ignored), than this would suffice:

<xsl:template match="page:lin k">
<a>
<xsl:attribut e name="href">
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
<xsl:copy-of select="node()[not(self::page: var)]"/>
</a>
</xsl:template>

############### ############### ##

Does this help, or am I still not understanding your question?

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #7
Joris Gillis wrote:
that did not help,
let me give an example:

<page:link page="pages/medewerker.page .xml">
<page:var>
<page:name>id </page:name
<page:value>val ue</page:value>
</page:var>
<page:var>
<page:name>id 2</page:name
<page:value>val ue2</page:value>
</page:var>
Bla <center>Bla <b>Bla</b></center>
</page:link>
This should be transformed to:

<a href="/index.php?page= pages/medewerker.page .xml&id=value&i d2=value2">
Bla <center>Bla <b>Bla</b></center>
</a>

It works for me with these templates:

############### ############### #############
<xsl:template match="page:lin k">
<a>
<xsl:attribut e name="href">
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</a>
</xsl:template>

<xsl:template match="*" mode="ignore">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</xsl:copy>
</xsl:template>

############### ############### #############
But if the xml structure really is a simple as in this example (no
deeper nested elements that should be ignored), than this would suffice:

<xsl:template match="page:lin k">
<a>
<xsl:attribut e name="href">
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
<xsl:copy-of select="node()[not(self::page: var)]"/>
</a>
</xsl:template>

############### ############### ##

Does this help, or am I still not understanding your question?

regards,


Thanks for your help,

i think i fout a solution.
Jul 20 '05 #8
On Sat, 30 Oct 2004 15:33:01 +0200, Tjerk Wolterink <tj***@wolterin kwebdesign.com> wrote:
Joris Gillis wrote:

<snip>
############### ############### ##

Does this help, or am I still not understanding your question?

regards,


Thanks for your help,

i think i fout a solution.

which was...?

Jul 20 '05 #9
Hi,
suppose i have a dom like this:
<a>
- <b>
- <b>
- <d>
- </b>
- <c>
- <e/>
- </c>
- <f/>
</a>
now to select al f child nodes of a, is : a[f]
That's not correct actually. It should be a/f
but how do i select all child nodes of a that are not equeal to f??
a[!f] does not work.
How do i do that??!?!?!


is it this?

a[child:* != f]


What you need is:

a/*[not(self::f)]
or
a/*[local-name()!='f']

regards,

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 20 '05 #10

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

Similar topics

1
2425
by: Vijay | last post by:
Hi Can anybody explain what self::* means in Xpath. I understand that "self" means the context node itself and * means any node type. So I thought self::* meant all the child nodes of context, but I some where read that self::* mean ".", the context itself. Can somebody please explain this. Vijay
2
2624
by: nkunapa | last post by:
Hi: Is there a way in XPATH to find the nearest node of the node in context with a certain attribute value. Here is my problem. I have the following XML and I am trying to add all the nodes with attribute value LNum=1 as child nodes of the nearest node above it with attribute LNum=0....and add all the nodes with attribute value LNum=2 as child nodes of the nearest node above it with attribute LNum=1 and so on. The LNum value can go...
7
1805
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange"; XmlElement crsElement = (XmlElement)m_colorRangeSwatchDoc.SelectSingleNode(expr); bool fr = bool.Parse(crsElement.GetAttribute("fixed").ToString()); The element returned is always the 1st, All Blue Colors, why doesn't the expression...
1
4000
by: Dave | last post by:
Is it possible to get <codes><code id="4"><name>abc</name></code></codes from the XML below in single SelectSingleNode/xPath expression step OR is going to have to be a multi=step process of using SelectNodes with an XPath expression to return all the nodes with "code id = 4", iterate the NodeList, re-build the XML string and wrap it with "<codes>" again? I wasn't sure if you can somehow return the parent node when using xPath to find...
2
2430
by: nick_tucker | last post by:
Hi, I am very new to XML and XPATH. I have made a sample XML fileto ask my question. <?xml version="1.0" encoding="utf-8"?> <Test> <A> <B> <C> <D>
4
4090
by: eric.goforth | last post by:
In an xsl stylesheet, I have <xsl:when test="string-length(//mystuff) &gt; 0"> <xsl:attribute name="someattribute">blahblahblah</xsl:attribute> </xsl:when> In the xml that mystuff is several layers deep, does the // do a search in the xpath? <test>
3
3315
by: SD | last post by:
Hi, How can i get all the nodes with attribute Name = "Publisher" or Name="Administrator" using XPath query and C# for this xml doc? <GetRoleCollectionFromUser xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\"> <Roles> <Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\" Type=\"2\" />
3
2854
by: jmagaram | last post by:
I have a DataSet I want to work with as Xml using XmlDataDocument. I can't figure out how to query the resultant Xml using XPath. From the following XML below, what XPath query will return the list of orders for each Male customer? Because some tables in my DataSet have >1 foreign key columns, it is not possible to set up a nested DataRelation for all relationships - a DataTable can only be the child of at most one nested DataRelation. As...
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8576
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.