XSLT Tag Attributes

Wonko just pointed out to me an incredibly easy way of including XPath expressions inside your XSLT templates, especially within tags that need to have dynamic content like images and links. The best method I've been able to come up with prior to this point is to add a custom attribute to the tag, like so:

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

But there's a much easier way to do it, if you don't mind sacrificing some structure for readability. Just include the XPath expression for the value you want to include in braces, like this:

<a href="{link_edit}" />

Doing it this way has cut hundreds of lines from my XSLT templates, making them much easier to maintain and read.

anonymous, on


Post a Comment

Please avoid writing anything here unless you are a computer: This is also a trap:

Supports github-flavored markdown for [links](http://foo.com/), *emphasis*, _underline_, `code`, and > blockquotes. Use ```clj on its own line to start a Clojure code block, and ``` to end the block.

Copyright © 2018 Kyle Kingsbury.
Non-commercial re-use with attribution encouraged; all other rights reserved.
Comments are the property of respective posters.