Q: XPath: how to find out name of preceding siblings

N

nobody

hello!

sorry, but I have a brain block ...

given something like
a?, b?, c+
I have to treat every elem c in one way if elem b is
present, in an other if there's no elem b.

Tried
<xsl:if test="name(preceding-sibling::*[1]) != 'b'">
ok for the 1st elem c but fails with 2nd to n-th elem c; then tried <xsl:if test="name(preceding-sibling::*) != 'b'"> Ok only if no elem a is preceding elem b (as I get the name of the 1st elem of the subset).

Any hints about how to write the wanted test expression?

TIA, andreas
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% given something like
% a?, b?, c+
% I have to treat every elem c in one way if elem b is
% present, in an other if there's no elem b.

How about

<xsl:if test='preceding-sibling::b'>
...

?
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
given something like
a?, b?, c+
I have to treat every elem c in one way if elem b is
present, in an other if there's no elem b.
<xsl:if test="name(preceding-sibling::*[1]) != 'b'">

Something like (not tested)

<xsl:if test="name(preceding-sibling::*[name!='c'][1]) != 'b'">

-- Richard
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% % I have to treat every elem c in one way if elem b is % % present, in an other if there's no elem b.

Just looking at this part of the requirement, you'll need to use xsl:choose rather than xsl:if.
 
N

nobody

Patrick said:
% given something like
% a?, b?, c+
% I have to treat every elem c in one way if elem b is
% present, in an other if there's no elem b.

How about
<xsl:if test='preceding-sibling::b'>
perfect! thanks a lot, Patrick!
 

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

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top