Re: [none] (Wendy's question)

Subject: Re: [none] (Wendy's question)
From: korolkm@xxxxxxxxxxxxxxxxxxxx
Date: Fri, 26 Feb 1999 19:03:24 +0300
Wendy wrote:

> Within an XSL Stylesheet how can we dynamically change the select
attribute of
> "for-each" xsl element.
> Eg
>     <xsl:for-each select='Some Default'>
>     ...
>     </xsl:for-each>
> Now I want to dynamically transform the above xsl to the following xsl
>     <xsl:for-each select='ElementName[@value="Contents of a Variable"]'>
>     ...
>     </xsl:for-each>

I asked this question some days ago to Scott Boag (developer of LotusXSL
processor) and his answer was NO, THIS IS NOT POSSIBLE with current XSL
draft. In general this effect could be acheived the following way:
1) you put an Attribute Value Template (AVT) that references some constant
into attribute:
     <xsl:for-each select="ElementName[@value='{constant(some-constant)}']">
2) before running your XSL processor you programmatically set value to this
	processor.setConstant ("some-constant", "Contents of a variable");
3) run your porcessor. During the run value of the constant will be
substituted and effect in actual processing of 
           <xsl:for-each select="ElementName[@value='Contents of a
I do not know about other processors, but LotusXSL has this nice
"setConstant" function.

This sounds nice, but as Scott explaned, current draft allows AVT to be used
everywhere with exception of "select" and "match" patterns. So, this elegant
approach is not possible and does not have any reasonable replacement
currently. I myself miss this approach very much. I tried it with an old
version of LotusXSL that wrongly allowed this forbidden behaviour and found
it very comfortable.

The alternatives are:
1) Preprocess text of your XSL document and perform text substitution for
"Some Default" string. Then parse preprocessed stylesheet and apply it to
XML file.
2) Do similar thing with DOM tree of your XSL stylesheet: find a node that
needs to be substituted, substitute it with actual value of template and
then apply this preprocessed DOM tree to an XML document. This is more
preferrable than first approach if you need to apply your stylesheet
template many times - you do not need to reparse it every time.

But to my taste these two alternative approaches are not as elegant as the
forbidden one :-(


 XSL-List info and archive:

Current Thread