Riding an XSLT Bike

I might be the only one but I've always found that XSLT is nothing like riding a bike; either I've been doing it lately and it's my friend or I haven't and it makes my head hurt.

I'm kinda into XML as a data transport format (JSON is cool too) right now. We've been writing transforms to produce some user friendly windows into our data warehouse CI process.

Not for the first time in my life, I find my self constrained to v1.0 but wanting to do some stuff that's much easier in v2.0. Hopefully the example below will help someone out one day (even if it's me in a year or two)...

I want to create a simple table from the following XML:


I want to replace "Gary" with "John" and I want to inject links to the (conveniently) wrapped file names.

Here's my transform:


Here's (a screenshot of) the output:


The following are worth pointing out:

1. The use of "copy-of" (instead of "value-of") whenever my "thing" contains markup that I want to keep as markup
2. The use of "xsl:attribute name=" to allow me to inject values into node attributes
3. The use of recursion for multiple replacements
4. The use of variables (in "tidyUp") to stack transformations

comments powered by Disqus