Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath Problem: Select all childnodes, that names are neither "name1" nor "name2"

Reply
Thread Tools

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

 
 
adurth@cs.tu-berlin.de
Guest
Posts: n/a
 
      02-26-2007
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

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      02-26-2007
On Feb 26, 11:01 am, (E-Mail Removed)-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

 
Reply With Quote
 
 
 
 
adurth@cs.tu-berlin.de
Guest
Posts: n/a
 
      02-26-2007
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 wouldnt 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

 
Reply With Quote
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      02-26-2007
Please quote what you're replying to.

On Feb 26, 12:13 pm, (E-Mail Removed)-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 wouldnt 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

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      02-26-2007
In article <(E-Mail Removed) om>,
<(E-Mail Removed)> 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.
 
Reply With Quote
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      02-26-2007
On Feb 26, 2:02 pm, (E-Mail Removed) (Richard Tobin)
wrote:
> In article
> <(E-Mail Removed) om>,
> <(E-Mail Removed)> 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

 
Reply With Quote
 
adurth@cs.tu-berlin.de
Guest
Posts: n/a
 
      02-26-2007
On 26 Feb., 14:17, (E-Mail Removed) 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

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      02-26-2007
In article <(E-Mail Removed) om>,
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem: neither urllib2.quote nor urllib.quote encode the unicodestrings arguments Valery Khamenya Python 3 10-05-2008 10:16 AM
After Crash No Boot neither from HDD nor from CD Arno Windows 64bit 12 06-01-2006 10:19 AM
A text which neither gets very narrow nor disappears Luigi Donatello Asero HTML 21 01-06-2006 11:32 PM
c is a low-level language or neither low level nor high level language pabbu C Programming 8 11-07-2005 03:05 PM
Neither Han nor Greedo will shoot first Mark W DVD Video 6 12-05-2003 07:45 AM



Advertisments