xsl-list
[Top] [All Lists]

Re: [xsl] Dynamic variables?

2010-11-28 11:45:09
Peter Davis wrote:
I think this may be addressed in the FAQ, under "what can't XSLT do,"
but I'm not sure I'm understanding it correctly, specifically the
question about referencing a variable whose name is referenced as an
attribute in the XML.  For example, suppose the XML looks like this:

<styles>
<style name="basic" typeface="Optima" weight="normal" slant="roman"/>
<style name="emphatic" typeface="Optima" weight="bold" slant="italic"/>
</styles>
. . .
<p style="basic">This paragraph contains some<span
style="emphatic">emphatic</span>  text.</p>

I want to remember those "style" definitions so I can emit appropriate
code when they are referenced. Is there a way to create variables whose
names come from the @name attribute of the style elements, and reference
them later by those names?

Consider to post the sample output you want to generate from above input.
I think keys can help e.g.
  <xsl:key name="k1" match="styles/style" use="@name"/>
and
  <xsl:template match="*[(_at_)style]">
    <xsl:variable name="style" select="key('k1', @style)"/>
    <!-- now use the found style here -->
    ...
  </xsl:variable>
--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--