Quick Tip – Shorthand Variable References in XSLT

Here’s a quick tip – next time you’re writing some XSL and want to include a variable within the attribute value of a node, don’t waste time & code doing something like this:

<xsl:variable name="VarName" select="SomeData"/>
  <xsl:attribute name="AttrName">
    <xsl:value-of select="$VarName"/>

Instead, you can use this shorthand notation for referencing a variable directly within an element attribute:

<xsl:variable name="VarName" select="SomeData"/>
<MyElement AttrName="{$VarName}"/>


Comments are closed.