XPath Problem: Select all childnodes, that names are neither "name1" nor "name2"

Discussion in 'XML' started by adurth@cs.tu-berlin.de, Feb 26, 2007.

  1. -berlin.de

    -berlin.de Guest

    Hi!
    I wanna copy all childnodes of the current nodes except those with
    basenames "name1" or "name2".
    Something like
    <xsl:copy-of select=" basename not equal ('name1' or 'name2') "/>

    Can someone help please?
    Thanks,
    Andreas
     
    -berlin.de, Feb 26, 2007
    #1
    1. Advertising

  2. -berlin.de

    Guest

    On Feb 26, 11:01 am, -berlin.de wrote:
    > I wanna copy all childnodes of the current nodes except
    > those with basenames "name1" or "name2".


    What do you mean by 'basename'? Element name, attribute,
    child element? Please stick to standard terms if you want
    others to understand you.

    > <xsl:copy-of
    > select=" basename not equal ('name1' or 'name2') "/>


    You don't have any previous coding experience, do you?

    Depending on what precisely you intend to do, the XPath
    expression might look like:

    *[not(self::name1) and not(self::name2)]

    *[local-name()!='name1' and local-name()!='name2']

    *[@basename!='name1' and @basename!='name2']

    *[basename!='name1' and basename!='name2']

    Note that it is elementary good design to implement
    template-based copying instead of copy-of (untested):

    <xsl:template match="foo">
    <xsl:apply-templates mode="selective-copy"/>
    </xsl:template>
    <xsl:template match="name1|name2" mode="selective-copy"/>
    <xsl:template
    match=
    "
    *[not(self::name1) and not(self::name2)]
    " mode="selective-copy">
    <xsl:copy-of select="."/>
    </xsl:template>

    This way you can easily reuse selective-copy whenever
    needed, and you would only need to change anything in one
    place in case you needed alterations to the algorithm.

    --
    Pavel Lepin
     
    , Feb 26, 2007
    #2
    1. Advertising

  3. -berlin.de

    -berlin.de Guest

    Hi!
    'baseName' is a standard term in VB, it returns the element name.
    Does it matter if I have coding experience?
    Yes, template is much better. But it wouldn´t have fit in one column,
    would it? Everyone has understood me without reading several lines of
    unformatted, unhighlighted code.
    Thank you very much, your suggestion works fine.

    Greetings,
    Andreas
     
    -berlin.de, Feb 26, 2007
    #3
  4. -berlin.de

    Guest

    Please quote what you're replying to.

    On Feb 26, 12:13 pm, -berlin.de wrote:
    > 'baseName' is a standard term in VB, it returns the
    > element name.


    This is not a VB newsgroup, however. When asking
    VB-specific questions in a VB newsgroup, by all means, go
    ahead and use the terms accepted in the VB
    community--that's the right thing to do anyway. On the
    other hand, when asking questions in an XML newsgroup,
    using VB-specific terms is quite counter-productive.

    > Does it matter if I have coding experience?


    That's something you'll have to ask your employer, not me.
    I just made an observation regarding the fact that:

    basename not equal ('name1' or 'name2')

    ....is a somewhat surprising way to express what J. Random
    Codegrinder would probably express as either:

    basename not equal 'name1' and basename not equal 'name2'

    ....or:

    basename not in ( 'name1' , 'name2' )

    > Yes, template is much better. But it wouldn´t have fit
    > in one column, would it?


    It was just a random observation. Well, not entirely
    random, there was my doubtlessly nefarious intention to
    give you a pointer on good practices in case you haven't
    realised that yourself yet.

    > Everyone has understood me without reading several lines
    > of unformatted, unhighlighted code.


    In this case you're absolutely right. Note however, that
    for harder questions it's a good practice to post what is
    commonly called 'minimum complete example'; and in that
    case you should take care of the formatting while my gvim
    will take care of highlighting.

    --
    Pavel Lepin
     
    , Feb 26, 2007
    #4
  5. In article <>,
    <> wrote:

    >That's something you'll have to ask your employer, not me.
    >I just made an observation regarding the fact that:
    >
    > basename not equal ('name1' or 'name2')
    >
    >...is a somewhat surprising way to express [...]


    It's not *that* implausible. For example, in Python you can say:

    basename in ('name1', 'name2')

    and in XPath (!) you can test whether the foo attribute is equal to
    either the bar or baz attribute by saying:

    @foo = (@bar | @baz)

    which is really very similar. (There is a trap for the unwary in
    using != in this case.)

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Feb 26, 2007
    #5
  6. -berlin.de

    Guest

    On Feb 26, 2:02 pm, (Richard Tobin)
    wrote:
    > In article
    > <>,
    > <> wrote:
    > >That's something you'll have to ask your employer, not
    > >me. I just made an observation regarding the fact that:

    >
    > > basename not equal ('name1' or 'name2')

    >
    > >...is a somewhat surprising way to express what J.
    > >Random Codegrinder would probably express as either:

    >
    > > basename not equal 'name1' and basename not equal
    > > 'name2'

    >
    > >...or:

    >
    > > basename not in ( 'name1' , 'name2' )

    >
    > It's not *that* implausible. For example, in Python you
    > can say:
    >
    > basename in ('name1', 'name2')


    Well, I'm obviously aware of facilities like that in many
    of the modern programming languages since I explicitly
    mentioned it in the part of my previous post you snipped.

    > and in XPath (!) you can test whether the foo attribute
    > is equal to either the bar or baz attribute by saying:
    >
    > @foo = (@bar | @baz)


    Mind-boggling. Note however, that unless I'm much mistaken,
    | is very different from or, and not in the way | is
    different from || in C either. = is not precisely 'equal'
    when working with nodesets, too.

    --
    Pavel Lepin
     
    , Feb 26, 2007
    #6
  7. -berlin.de

    -berlin.de Guest

    On 26 Feb., 14:17, wrote:

    >
    > Well, I'm obviously aware of facilities like that in many
    > of the modern programming languages since I explicitly
    > mentioned it in the part of my previous post you snipped.
    >


    Yes, you are obviously a code-guru and I bow in awe of such
    wisdom ;)).
    Never mind I just find the emotions often coming along with such
    unimportant matters quite funny.

    Greets,
    Andreas
     
    -berlin.de, Feb 26, 2007
    #7
  8. In article <>,
    <> wrote:

    >> It's not *that* implausible. For example, in Python you
    >> can say:
    >>
    >> basename in ('name1', 'name2')


    >Well, I'm obviously aware of facilities like that in many
    >of the modern programming languages since I explicitly
    >mentioned it in the part of my previous post you snipped.


    Oh yes, so you did.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Feb 26, 2007
    #8
    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. Luigi Donatello Asero

    A text which neither gets very narrow nor disappears

    Luigi Donatello Asero, Oct 3, 2005, in forum: HTML
    Replies:
    21
    Views:
    901
    Jonathan N. Little
    Jan 6, 2006
  2. pabbu
    Replies:
    8
    Views:
    768
    Marc Boyer
    Nov 7, 2005
  3. Valery Khamenya
    Replies:
    3
    Views:
    744
  4. Jerry Hill
    Replies:
    0
    Views:
    499
    Jerry Hill
    Oct 4, 2008
  5. steveski
    Replies:
    3
    Views:
    828
    Ken Cox [Microsoft MVP]
    Jan 26, 2005
Loading...

Share This Page