XPATH: Selecting child nodes wich are NOT equal to

Discussion in 'XML' started by Tjerk Wolterink, Oct 29, 2004.

  1. 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??!?!?!
    Tjerk Wolterink, Oct 29, 2004
    #1
    1. Advertising

  2. 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]
    Tjerk Wolterink, Oct 29, 2004
    #2
    1. Advertising

  3. Tjerk Wolterink

    Joris Gillis Guest

    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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Oct 29, 2004
    #3
  4. 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?
    Tjerk Wolterink, Oct 29, 2004
    #4
  5. Tjerk Wolterink

    Joris Gillis Guest

    > <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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Oct 29, 2004
    #5
  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>

    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?
    Tjerk Wolterink, Oct 30, 2004
    #6
  7. Tjerk Wolterink

    Joris Gillis Guest

    > 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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Oct 30, 2004
    #7
  8. 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.
    Tjerk Wolterink, Oct 30, 2004
    #8
  9. Tjerk Wolterink

    Jeff Kish Guest

    On Sat, 30 Oct 2004 15:33:01 +0200, Tjerk Wolterink <> 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...?
    Jeff Kish, Nov 1, 2004
    #9
  10. Tjerk Wolterink

    Joris Gillis Guest

    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/
    Joris Gillis, Feb 7, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olivier Wulveryck
    Replies:
    1
    Views:
    658
    Andrew Thompson
    Sep 14, 2004
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,365
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    391
    Patrick TJ McPhee
    Jun 17, 2004
  4. Yoav Shapira
    Replies:
    3
    Views:
    1,094
    Yoav Shapira
    Mar 8, 2006
  5. Replies:
    1
    Views:
    555
    Soren Kuula
    Aug 24, 2006
Loading...

Share This Page