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 <ala_NO@SPAM_context.ch>
 
P

Patrick TJ McPhee

% 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'>
...

?
 
R

Richard Tobin

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
 
P

Patrick TJ McPhee

% % 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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top