Link to home
Start Free TrialLog in
Avatar of pennypiper
pennypiper

asked on

Conditionally change value of element

Hello,

Assume the following XML file:

<root>
 <A>
     <A1>0</A1>
     <A1>11</A1>
     <A1>11</A1>
 </A>
 <B>
   <B1>2</B1>
   <B1>3</B1>
 </B>
 <C/>
</root>

I need an XSLT example which will change any <A1> with a value of "0" to "11".  Everything else in the document stays the same.  

I also need an XSLT example which will change the value of any <A1> with value of "0" to "11" if and only if the value of any <B1> element is "2".  Again, everything else in the document should stay the same.

Thanks!
SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pennypiper
pennypiper

ASKER

Thanks abel and Gertone!
(Sorry for the weird point split -- it made me give a minimum of 20 points per reply.)
> as you said using the //B1[ text() = '2'] can be very very very slow ,
exactly (but with XSLT 2.0, Saxon, it's internally changed to a key anyway, I believe, so depending on your processor it doesn't need to be slow, but it's bad design anyhow)

> Hi abel, it has been a while :-)
yep. It has been slow on the XSLT side for some months. But who knows... here comes the competition :)

@pennypiper: you're welcome