XPATH: Selecting child nodes wich are NOT equal to

T

Tjerk Wolterink

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??!?!?!
 
T

Tjerk Wolterink

Tjerk said:
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]
 
J

Joris Gillis

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,
 
T

Tjerk Wolterink

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?
 
J

Joris Gillis

<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,
 
T

Tjerk Wolterink

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?
 
J

Joris Gillis

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,
 
T

Tjerk Wolterink

Joris said:
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.
 
J

Joris Gillis

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top