We have an XML file that we are trying to figure out a way to use dynamically.
the basics are this:
<part>
<...>
<fldMinPriceUSD>100.00</fldMinPriceUSD>
<fldMaxPriceUSD>110.00</fldMaxPriceUSD>
<fldMinPriceCAD>120.00</fldMinPriceCAD>
<fldMaxPriceCAD>130.00</fldMaxPriceCAD>
</part>
for each part that we’ve got, we want to use xslt on it to grab the part price based on the currency sent in through a parameter. We don’t want to use if-elses because we might want to grow the list of currencies (EUR, GBP, etc.) without changing our templates.
So, we’d want to use the $dealerCurrency parameter (that would be USD, CAD, etc.) to concat with fldMinPrice to grab that value. Is this sort of thing even possible? I’ve tried a number of things, but none seem to work.
What I’ve tried so far is this:
<xsl:value-of select="format-number(str[@name=concat('fldMinPrice', $dealerCurrency)], '#.00')"/>
and this doesn’t seem to work. Any suggestions?
You are almost there. At the moment, by using str and @name you are looking for an element called str which has an attribute called name with a value of ‘fldMinPriceUSD’. What you need is the local-name() function, along with node() to match any node.
i.e. Match any node, with a name (excluding namespaces) of ‘fldMinPrice’ + your currency code.