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]
Other format: [Raw text]

Re: Wishes for XSL revisions ...


Andrew Welch wrote:

>1.  Is there ever a good time to use a for-each?

To paraphrase Jeni's comment of a couple of weeks ago: if to
understand the body of a template you need to know the select clause
which triggers it, then for-each could be the right solution.
Dimitri's suggestion of changing context in order to do a key() on an
input document is one example, Jeni mentioned the use of position()
within the template body.

I haven't proved this mathematically, but I suspect it is true that
*any* XSLT program may be expressed either by:

a) apply-templates only (with lots of modes)
or
b) for-each only (with lots of chooses, and with recursive named
templates to handle arbitrary recursion in the input docment)

For any particular purpose one method will be uglier than the other.
Currently apply-templates wins most arguments, and will win even more
come XSLT2.0/XPath2.0 when for example you can write
document()/key(...).  There is also a new contest to keep the
theorists busy, should one use xsl:if or XPath if() ?

There may be a parallel with the argument about imperative languages
and the goto statement.  There are clear and fairly common patterns
where goto would be easier to understand and more maintainable, but
the potential abuses are such that we do not design languages with
goto any more.  Maybe for-each will suffer the same fate.

>2.  If a variable cannot be changed after it has been assigned, why call it
>a variable?
Because it isn't a constant ;-)
Usually.
You cannot in general work out what the value of a variable will be
just by looking at the XSLT program.  You need to see the input
document too (to be precise, that part of the input document which
makes up the current context).

What else would one call it?  Value perhaps?  But then we would have
to talk about a value's value.  Expression?  In the sense that one can
eliminate the variable name by substituting (context X expression)
wherever you see $name.  (Thats the difference from imperative
languages that Dimitri pointed out: the substitution would have to
include some of the program state from an earlier point in time, hence
the added opportunities for the programmer to make a mistake).

>The above makes XSLT non-intuitive, and therefore harder to learn.  Is there
>another language where you cannot change the value of a variable?
>
I think all of them except for imperative languages, which so far we
have used for computers for historical reasons.
'My dog is a Spaniel'
'My dog' is clearly a variable, but how would one assign to it?

Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@melvaig.co.uk

 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]