XSL - variable within a loop

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I am almost completely new to xsl (starting learning it about a week ago) and I was hoping someone could help me with the following.
Lets say I have the following xml:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ISO-8859-1<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Green; <!-- Edited by XMLSpy® -->
<span style="color:Blue; <<span style="color:#A31515; catalog<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Empire Burlesque<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Bob Dylan<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Columbia<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >Unknown<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1985<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Hide your heart<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Bonnie Tyler<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >CBS Records<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >9.956<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1988<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Greatest Hits<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Dolly Parton<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >RCA<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >9.9523<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1982<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Still got the blues<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Gary Moore<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Virgin records<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >10.2345<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1990<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Eros<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Eros Ramazzotti<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >EU<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >BMG<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >9.12345<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1997<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >One night only<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Bee Gees<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Polydor<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >10.12333<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1998<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Sylvias Mother<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Dr.Hook<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >CBS<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.4098<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1973<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Maggie May<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Rod Stewart<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Pickwick<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.4456<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1990<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Romanza<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Andrea Bocelli<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >EU<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Polydor<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >10.889<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1996<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >When a man loves a woman<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Percy Sledge<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Atlantic<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.723<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Black angel<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Savage Rose<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >EU<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Mega<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >10.345<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1995<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >1999 Grammy Nominees<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Many<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Grammy<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >10.243<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1999<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >For the good times<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Kenny Rogers<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Mucik Master<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.955<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1995<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Big Willie style<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Will Smith<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Columbia<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >9.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1997<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Tupelo Honey<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Van Morrison<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Polydor<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.20<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1971<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Soulsville<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Jorn Hoel<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >Norway<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >WEA<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >7.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1996<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >The very best of<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Cat Stevens<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Island<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1990<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Stop<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Sam Brown<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >A and M<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1988<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Bridge of Spies<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >T`Pau<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Siren<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >7.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Private Dancer<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Tina Turner<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Capitol<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.958<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1983<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Midt om natten<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Kim Larsen<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >EU<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Medley<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >7.80<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1983<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Pavarotti Gala Concert<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Luciano Pavarotti<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >DECCA<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >9.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1991<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >The dock of the bay<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Otis Redding<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Atlantic<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >7.90<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Picture book<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Simply Red<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >EU<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >Elektra<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >7.20<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1985<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Red<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >The Communards<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >UK<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >London<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >Not Known<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Unchain my heart<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Joe ****er<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >EMI<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >8.20<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title<span style="color:Blue; >Californication<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; artist<span style="color:Blue; >Red Hot Chili Peppers<span style="color:Blue; </<span style="color:#A31515; artist<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >USA<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; company<span style="color:Blue; >EMI<span style="color:Blue; </<span style="color:#A31515; company<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >?????????<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >1987<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; cd<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; catalog<span style="color:Blue; >

[/code]


(almost the same as here: http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog )

and what I want is html that produces a table with each Title, Artist, and Price. However, if the price has more than two decimal places I want it formatted to 2 decimal places, and if the price is not a numeric value then I want the "The price for this
item is unknown" displayed rather than what is listed in the xml above....
So...as a basic template I have (also taken from the link above)...

<div style="color:Black;background-color:White; <pre>
<?xml version="1.0" encoding="ISO-8859-1"?>

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Blue; "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Blue; "/"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; html<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h2<span style="color:Blue; >My CD Collection<span style="color:Blue; </<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; border<span style="color:Blue; =<span style="color:Blue; "1"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr <span style="color:Red; bgcolor<span style="color:Blue; =<span style="color:Blue; "#9acd32"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th<span style="color:Blue; >Title<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th<span style="color:Blue; >Artist<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th<span style="color:Blue; >Price<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Blue; "catalog/cd"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; ><span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Blue; "title"<span style="color:Blue; /><span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; ><span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Blue; "artist"<span style="color:Blue; /><span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Green; <!-- !-->
<span style="color:Green; <!-- To Be Decided !-->
<span style="color:Green; <!-- !-->
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >



<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; html<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >



[/code]

<br/>
so basically in the to be decided section in the above code I have been toying with a couple of things, but I am not having any luck..
Some of the things I tried included using an if statement similar to the following:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xls<span style="color:Blue; :<span style="color:#A31515; if <span style="color:Red; test<span style="color:Blue; =<span style="color:Blue; "string(format-number(price, "##.##)) = NaN"<span style="color:Blue; >
The price for this item is unknown
<span style="color:Blue; </<span style="color:#A31515; xls<span style="color:Blue; :<span style="color:#A31515; if<span style="color:Blue; >
[/code]

but it doesnt seem to like the if statement...
and the other idea was to use:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Blue; "myPrice" <span style="color:Red; select<span style="color:Blue; =<span style="color:Blue; "price"<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Blue; "string(number($myPrice)) = NaN"<span style="color:Blue; >
The price for this item is unknown
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Blue; "format-number($myprice, ##.##)"<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
[/code]

<br/>
but I then I discovered I cant update the value of a variable in xsl. Does anyone have any ideas regarding how I can do this?
Thanks

View the full article
 
Back
Top