By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Feb 26 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Feb 26, 11:01 am, adu...@cs.tu-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 '07 #2

P: n/a
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

Feb 26 '07 #3

P: n/a
Please quote what you're replying to.

On Feb 26, 12:13 pm, adu...@cs.tu-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 '07 #4

P: n/a
In article <11**********************@8g2000cwh.googlegroups.c om>,
<p.*****@ctncorp.comwrote:
>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.
Feb 26 '07 #5

P: n/a
On Feb 26, 2:02 pm, rich...@cogsci.ed.ac.uk (Richard Tobin)
wrote:
In article
<1172490171.081824.102...@8g2000cwh.googlegroups.c om>,
<p.le...@ctncorp.comwrote:
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 '07 #6

P: n/a
On 26 Feb., 14:17, p.le...@ctncorp.com 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

Feb 26 '07 #7

P: n/a
In article <11*********************@q2g2000cwa.googlegroups.c om>,
<p.*****@ctncorp.comwrote:
>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.
Feb 26 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.