Mike West — Web Application Developer

For future reference:

Curly braces in the attributes of XSLT document’s elements are interpreted as XPATH expressions to be evaluated. This, generally, is fine: I like shortcuts. I don’t, however, like them when they interfere with my ability to embed JavaScript hacks into a document.

You may be thinking to yourself: “Mike, you shouldn’t embed JavaScript into an element’s attributes! That’s simply idiotic!” You’d be right, of course. But assume for the moment that I had a good reason for doing it (in this particular case, the link simply doesn’t work at all without JavaScript. which is also bad. but something I can’t do anything about right now. don’t do this at home, kids.). In that obscure case, I’d need to remember to set the attribute via the magical <xsl:attribute> element.

<a>
    <xsl:attribute name="href">
        http://curlyquotes.com/i/can/use/{/and/}/yay!/
    </xsl:attribute>
</a>

Now you know. And now I’ll be able to look this up in a few weeks when I have no idea what my code’s doing. :)

Also: I hate XSLT.

Mike West is a web application developer living in Munich, Germany. Professionally programming for the web since 2000, he's available for contract work now a web developer at Yahoo! Germany. Read Mike's bio, or drop him an e-mail.

Recent Articles


Comments

you could also force the xpath inside the attribute to be rendered as a string.

<a href=”{string(‘http://curlyquotes.com/i/can/use/{/and/}/yay!/’)}”>me link</a>

Posted By: Miguel de Melo 16. June 2007, 12:30

Thanks, Miguel. I didn’t know that… XPATH is obviously not my area of expertise. In general, this is a great tip!

I think this might have made my particular situation a little more complicated, though, as I actually had single-quotes inside the string along with the curly braces. Messy, eh? My XSLT code is currently more or less a collection of lessons about what not to do… :)

Posted By: Mike West 16. June 2007, 21:47

Comments Closed

Comments are closed after 6 weeks to avoid the icky comment spam we all loathe. Sorry if you missed the opportunity, but you can always drop me an e-mail!

flickr Photostream

Yahoo!'s Munich Office
atom:title
atom:title
atom:title