[XML4Lib] XSLT call name of variable dynamically?
Walker, David
dwalker at calstate.edu
Thu Feb 5 15:58:01 EST 2009
Hopefully this makes sense:
I've got this app that basically does a bunch of stuff, creates some XML, and then uses XSLT to build the end-user interface in HTML.
We've been using global <xsl:variable>s to hold text in the system. Each implementation has a local stylesheet that imports the master one, so you can override the default system text by simply re-declaring the variable in the local stylesheet. Works well.
What I'm working on now is breadcrumbs in the system. Right now we just have a big, hideous <xsl:choose> block that figures out which 'page' you are on, and then outputs some HTML for breadcrumbs. Doesn't work so well.
What I'd _like_ to do is have the system itself create the breadcrumb hierarchy in the XML, and then simply loop over that in the XSLT, outputting the link and text. But I'd like the text itself to come from an XSLT variable, not from the XML, so we can keep our override scheme.
I can have the XML tell the XSLT which variable to use, but I'm back to a (slightly less) hideous choose block:
<xsl:choose>
<xsl:when test="label = 'text_breadcrumb_databases_categories'">
<xsl:copy-of select="$text_breadcrumb_databases_categories" />
</xsl:when>
[etc.,etc.]
</xsl:choose>
The other option I've tried is to create templates that match on the name of the XML node, so like this:
<xsl:template match="text_breadcrumb_databases_categories">some text</xsl:template>
. . . and then in the breadcrumb section, something like this
<xsl:for-each select="breadcrumb">
<a href="{link}"><xsl:apply-templates select="label" /></a>
</xsl:for-each>
But I've had some problems with this approach. Need to figure it out, unless there is some better way I'm not thinking of?
--Dave
==================
David Walker
Library Web Services Manager
California State University
http://xerxes.calstate.edu
________________________________________
From: Alexander Johannesen [alexander.johannesen at gmail.com]
Sent: Thursday, February 05, 2009 12:10 PM
To: Walker, David
Cc: xml4lib at webjunction.org
Subject: Re: [XML4Lib] XSLT call name of variable dynamically?
On Thu, Feb 5, 2009 at 21:00, Walker, David <dwalker at calstate.edu> wrote:
> <xsl:value-of select="${$foo}" />
Nope, sorry, all variables and references to variables are static by
design (functional programming vs. imperative programming). What are
you trying to do, though?
Regards,
Alex
--
---------------------------------------------------------------------------
Project Wrangler, SOA, Information Alchemist, UX, RESTafarian, Topic Maps
------------------------------------------ http://shelter.nu/blog/ --------
More information about the XML4Lib
mailing list