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:var iable>
<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
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:var
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
excellent, thats got it.
Im assuming it is case sensitive, is there away of mitigating this along with the spacing too?
Thanks
Im assuming it is case sensitive, is there away of mitigating this along with the spacing too?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What happens when I get onto cars with a colour that is two words? i.e. dark purple