This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Variable names *as* variables


> I have a feeling that what I'm trying to do can't be done without
> extensions, like Saxon's eval. Unfortunately I can't use an extension
> function for this case, and thought I'd fly it past the list to see if any
> of you have a brainstorm.

Yet it can be done without any extensions. Try to apply the following stylesheet
to your <someroot> sample. The key idea is that document('') returns the root of
the stylesheet itself; in this way, you can address pieces of the stylesheet as
if they were elements in the source document.

However, I think it isn't a good idea to intersperse style with data. IMO, you
should better put your location data into a separate XML file, marking them with
normal markup instead of xsl:variables. Then you can access them using
document() function, in the same way that I used to extract these data from the
stylesheet.

Regards,

Nikolai Grigoriev
RenderX

----------------------------------------------------------
<?xml version='1.0' encoding='ISO-8859-1'?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="utf-8"/>

<xsl:variable name="location1">Midtown</xsl:variable>
<xsl:variable name="location2">Greater Northeast</xsl:variable>
<xsl:variable name="location3">Dallas-Ft. Worth</xsl:variable>

<xsl:template match="event">
  <xsl:text>&#xA;Event of </xsl:text>
  <xsl:value-of select="@date"/>
  <xsl:text> takes place at:</xsl:text>
  <xsl:apply-templates select="locale"/>
  <xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template match="locale">
  <xsl:variable name="place" select="@place"/>
  <xsl:text>&#xA;   </xsl:text>
  <xsl:apply-templates select="document('')//xsl:variable[@name=$place]"/>
</xsl:template>

</xsl:stylesheet>






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]