[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Dynamic variables?

Subject: Re: Dynamic variables?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sun, 28 Nov 2010 17:52:03 +0000
Re:  Dynamic variables?
Variable names have to be known at compile time: you can't decide at run-time what variables to create, or what variables to reference.

In your rationale you say "

I want to remember those "style" definitions so I can emit appropriate
code when they are referenced.

Use of temporal language like this ("remember", "when") is always dangerous with XSLT; it's best to avoid thinking about XSLT computation as having a particular temporal order.

I think you want to define a key:

<xsl:key name="styleKey" match="style" use="@name"/>

and then when you come to process a <p> element you can find the relevant style using key('styleKey', @style).

Michael Kay
Saxonica

On 28/11/2010 17:36, 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?

Thank you,

-pd

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.