469,281 Members | 2,465 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

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 15771
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>value</page:value>
</page:var>
<page:var>
<page:name>id2</page:name <page:value>value2</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&id2=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:link">
<a>
<xsl:attribute name="href">
/index.php?page=<xsl:value-of select="@page"/>
<xsl:for-each select="page:var">
&amp;<xsl:value-of select="page:name"/>=<xsl:value-of
select="page:value"/>
</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>value</page:value>
</page:var>
<page:var>
<page:name>id2</page:name <page:value>value2</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&id2=value2">
Bla <center>Bla <b>Bla</b></center>
</a>


It works for me with these templates:

###########################################
<xsl:template match="page:link">
<a>
<xsl:attribute name="href">
/index.php?page=<xsl:value-of select="@page"/>
<xsl:for-each select="page:var">
&amp;<xsl:value-of select="page:name"/>=<xsl:value-of select="page:value"/>
</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:link">
<a>
<xsl:attribute name="href">
/index.php?page=<xsl:value-of select="@page"/>
<xsl:for-each select="page:var">
&amp;<xsl:value-of select="page:name"/>=<xsl:value-of select="page:value"/>
</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>value</page:value>
</page:var>
<page:var>
<page:name>id2</page:name
<page:value>value2</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&id2=value2">
Bla <center>Bla <b>Bla</b></center>
</a>

It works for me with these templates:

###########################################
<xsl:template match="page:link">
<a>
<xsl:attribute name="href">
/index.php?page=<xsl:value-of select="@page"/>
<xsl:for-each select="page:var">
&amp;<xsl:value-of select="page:name"/>=<xsl:value-of
select="page:value"/>
</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:link">
<a>
<xsl:attribute name="href">
/index.php?page=<xsl:value-of select="@page"/>
<xsl:for-each select="page:var">
&amp;<xsl:value-of select="page:name"/>=<xsl:value-of
select="page:value"/>
</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***@wolterinkwebdesign.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Vijay | last post: by
2 posts views Thread by nkunapa | last post: by
1 post views Thread by Dave | last post: by
4 posts views Thread by eric.goforth | last post: by
3 posts views Thread by SD | last post: by
3 posts views Thread by jmagaram | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.