XSLT Tip: Cut Verbose Attribute Code with Curly Braces

Wonko has highlighted a straightforward technique for embedding XPath expressions directly into XSLT template attributes, particularly for dynamic tags such as images and links. The conventional approach requires a custom attribute and multiple lines of code:

<xsl:attribute name="href">
<xsl:value-of select="link_edit" />
</xsl:attribute>
Edit

However, a more efficient alternative exists: place the XPath expression inside curly braces within the attribute itself.

<a href="{link_edit}">Edit</a>

This method trims hundreds of lines from XSLT templates, improving both readability and maintainability without sacrificing functionality.