[XML4Lib] XSLT call name of variable dynamically?

Walker, David dwalker at calstate.edu
Thu Feb 5 16:27:06 EST 2009


You mean like an XML file that holds the name of the text?  Yeah, I've considered this approach too. 

I prefer having it in XSLT variables, since we've done the other labels like that.  And it allows a site not simply to define text, but can to put XSLT code in the variable.  Which is handy sometimes.

--Dave

==================
David Walker
Library Web Services Manager
California State University
http://xerxes.calstate.edu
________________________________________
From: Luckabaugh, Joy H. (LNG-BET) [Joy.Luckabaugh at lexisnexis.com]
Sent: Thursday, February 05, 2009 1:23 PM
To: Walker, David
Cc: xml4lib at webjunction.org
Subject: RE: [XML4Lib] XSLT call name of variable dynamically?

Please ignore this if there is some reason this wouldn't work, but
couldn't you do something similar by using external entities (in local
files) to hold the text?

Joy

> -----Original Message-----
> From: xml4lib-bounces at webjunction.org
> [mailto:xml4lib-bounces at webjunction.org] On Behalf Of Walker, David
> Sent: Thursday, February 05, 2009 3:58 PM
> To: Alexander Johannesen
> Cc: xml4lib at webjunction.org
> Subject: RE: [XML4Lib] XSLT call name of variable dynamically?
>
> 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/ --------
>
> _______________________________________________
> XML4Lib mailing list
> XML4Lib at webjunction.org
> http://lists.webjunction.org/mailman/listinfo/xml4lib
>
>



More information about the XML4Lib mailing list