I’m passing in a bunch of key-value pairs as parameters to a XSL (date -> ’20th January’, author -> ‘Dominic Rodger’, …).
These are referenced in some XML I’m parsing – the XML looks like this:
<element datasource='date' />
At present, I can’t work out how to get 20th January out of these except with a horrible <xsl:choose> statement:
<xsl:template match='element'> <xsl:choose> <xsl:when test='@datasource = 'author''> <xsl:value-of select='$author' /> </xsl:when> <xsl:when test='@datasource = 'date''> <xsl:value-of select='$date' /> </xsl:when> ... </xsl:choose> </xsl:template>
I’d like to use something like:
<xsl:template match='element'> <xsl:value-of select='${@datasource}' /> </xsl:template>
But I suspect this isn’t possible. I’m opening to using external function calls, but want to avoid having to enumerate all possible map keys in my XSL. Any ideas?
Thanks,
Dom
Here is one possible solution, however I’d recommend grouping all parameters in a separate XML file and accessing them with the
document()function:When this transformation is applied on the following XML document:
the correct result is produced:
date = 01-15-2009
place = Hawaii
Do note the use of the
xxx:node-set()function (the EXSLT one is used here) to convert an RTF (Result Tree Fragment) to a regular xml document (temporary tree).