Posts Tagged ‘StringConcatenation’

Gotcha: don’t use ‘{$…}’ syntax or ‘$…’ syntax in XSL-XPath’s concat

<xsl:template match="cxml:Item" mode="col">
  <xsl:variable name="FILENAME" select="…someXPathQuery…"/>
  <xsl:variable name="IMAGE" select="concat(‘’, $FILENAME, ‘.png’)"/>

I got confused a bit today after a long day of fiddling with XSL and ClipFlair Activity Gallery’s CXML (Collection XML) data (as used in PivotViewer control), and didn’t understand why I couldn’t use an XSL variable’s (FILENAME in the sample above) calculated value inside the definition of another variable.

That other variable (IMAGE) was using “concat” function of XPath and I was getting a literal string concatenated, instead of the value of the FILENAME one.

After a while I noticed that I was using string quotes arround the respective argument passed to the “concat” function. One needs to use $FILENAME there, not ‘$FILENAME’ and of course not ‘{$FILENAME}’ (the last one is used inside say HTML argument values used for output, like <img href=”{$IMAGE}” />)

%d bloggers like this: