RE: [xsl] A variable in the test attribute of <xsl:if> ?

Subject: RE: [xsl] A variable in the test attribute of <xsl:if> ?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 26 Oct 2007 09:30:10 +0100
The other way to approach this is using higher-order functions. Rather than
pass the parameterized condition as a string containing an XPath expression,
pass it as a function. This is a much cleaner approach than passing strings
around, because you don't get syntax errors at run-time, you don't get all
the messy issues of context (especially namespace context), and of course it
should perform much better. Take a look at FXSL to see how this is achieved.
(Unfortunately Dimitre's documentation of FXSL does require a fairly high
level of computer science knowledge; someone really needs to write a guide
for novices, because the concepts really aren't that difficult.)

Passing strings and using xx:evaluate() is sometimes needed, for example
when the expression is constructed dynamically from interactive user input.
But in general, I'd go for using functions. Apart from anything else, FXSL
for XSLT 2.0 is pure XSLT with no vendor extensions.

Michael Kay
http://www.saxonica.com/ 


> -----Original Message-----
> From: John Horner [mailto:Horner.John@xxxxxxxxxx] 
> Sent: 26 October 2007 02:58
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] A variable in the test attribute of <xsl:if> ?
> 
> The reason I thought about doing this:
> 
> The XSL CMS I work with involves a lot of <xsl:copy-of> from 
> one file to another based on a wide variety of conditions, 
> say for instance a simple
>  
>    "(X = 'foo' and Y = 'bar')"
> 
> which is easily able to be parameterised -- you have a 
> "x-and-y-must-match-params.xsl" and you pass it a value for 
> X, a value for Y.
> 
> but for complex, specialised requirements like 
> 
>     "((X='foo' and Y='bar') or (Z='baz' and (A!='bof' or 
> B='bop'))) or (starts-with(C,'quux'))"
> 
> there's no sane way to generalise it and feed it params. You 
> end up with a large number of xsl files, each performing one 
> specific job.
> 
> If I could create a "must-match-this-if-clause.xsl" and feed 
> it the above string, it would be more efficient.
> 
> Any other ways to approach this problem?
> 
> 
> -----Original Message-----
> From: Florent Georges [mailto:lists@xxxxxxxxxxxx]
> Sent: Thursday, 25 October 2007 9:09 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] A variable in the test attribute of <xsl:if> ?
> 
> Michael Kay wrote:
> 
>   Hi
> 
> > As specified in EXSLT, dyn:evaluate() can return a value of 
> any type 
> > (including of course a boolean). But there may be 
> restrictions in the 
> > MSXML implementation, I don't know.
> 
>   Maybe the OP can find something else and avoid the need for 
> dyn:evaluate().  Almost everytime I saw the "need" for such a 
> feature, there were other ways to do the job, with more 
> restricted possibilities.  Such as testing an element name 
> and then testing its value against a sequence of strings, or 
> more elaborated things...
> 
>   But for that, the OP should tell us exactly what he wants and why.
> 
>   Regards,
> 
> --drkm
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
> ______________________________________________________________
> __________
> _____
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails 
> vers Yahoo!
> Mail 

Current Thread