Link to home
Start Free TrialLog in
Avatar of help-is-needed
help-is-needed

asked on

xslt for-each = $variable

Hi,

I would like to create a dynamic for each loop that only picks up the records that match a certain variable passed into the xsl.

So say I have a list of cars. I would like to do a for-each that picks up all cars that are red.

But set as a variable.

<xsl:variable name="colour">red</xsl:variable>

<xsl:for-each select="car[info/colour = $colour]">
XML
<cars>
 <car>
  <info>
   <colour>red</colour>
   <price>500</price>
   <make>ford</ford>
  </info>
  <history>
    <MOT>none</MOT>
  </history>
 </car>
 <car>
  <info>
   <colour>white</colour>
   <price>650</price>
  </info>
 </car>
</cars>

Doesn't seem to be working. I can get it working for numbers though, say do it for price and the variable is 500.

Thanks
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
Avatar of help-is-needed
help-is-needed

ASKER

ah, putting in the normalize-space worked.

What happens when I get onto cars with a colour that is two words? i.e. dark purple
normalize-space takes away all white-space (newlines, tabs, spaces, ...) in the beginning and at the end of the argument
and replaces each sequence of white-space (one or more newlines, spaces, tabs, ...) inside the argument with one space

"     dark          
purple      

"

will become
"dark purple"
for the compare,
which likely fits your purpose
excellent, thats got it.
Im assuming it is case sensitive, is there away of mitigating this along with the spacing too?

Thanks
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