Re: [xsl] A beef with XSLT Sometimes too complicated

Subject: Re: [xsl] A beef with XSLT Sometimes too complicated
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 18 Jul 2006 10:45:29 -0400
At 05:36 PM 7/17/2006, you wrote:
> So -- if I follow you -- nesting a for expression is a workaround for
> this gap only some of the time?

nesting the for never helps, you can use one for if the sequnce being
bound to the variable has exactly one item
let $x :=1 return ...
can be written in xpath as
for $x in 1 return ..

Ah.


but there is _no_ way in XPath to bind a value to a variable x such that
count($x)
has any value other than 1.
so
let $x := () return ...
and
let $x := (1,2) return ...
have no analogue in XPath.

Ah-hah. I think what's impeding my brain here is simply my inexperience with query languages in general, and in particular with applications of let constructs with variable cardinality (using the word "variable" as English, not XPath :-). (Outside the XSLT context, of course.)


Now, transformations I have experience with....

It does occur to me that what we are facing is a collective coming-to-grips with the question of queries-as-transformations and transformations-as-queries, both in the design choices made by the committees (facing their various requirement sets) and by the user communities who then use those designs. I'm inclined to think of queries as a subset of transformations, but then I would think that. Stepping back I suppose it's probably possible to define each in terms of the other. And it does seem that in the real world, transformations always include some query component (even if implicit as in <xsl:apply-templates/>) while queries mostly include some transformation component (or can be seen as transformations in themselves).

When XPath is used in XSLT it's only a minor inconvenience, you just
drop back into xslt and use
<xsl:variable name="x" select="()"/>
<xsl:variable name="x" select="(1,2)"/>
It might be more of a "problem" in oher XPath API, although less of
a problem than those API for XPath1, which don't let you bind variables
at all, as XPath1 has no binding expressions.

> In line with the question whether to prefer XPath or XSLT logic, can
> we see an example where we'd actually prefer to do it in XPath if we
> could? (I'd welcome entries from anyone.)

So if thinking about this "the xpath way" it's probably not much of a
problem, but increasingly when looking for xpath solutions you're going
to be lead by somone or some search engine to xquery solutions.

I think you mean the "XSLT Way" here, in Carlislese?


The fact that often you can get an xpath solution from an xquery solution by
replacing any let by for means that people will try that, but it's only
safe to do if you know the cardinality of the expression being bound is
always 1 (which you are unlikely to know if it's just some code found on
the web) I feel a faq coming on in this area...

Right.


Cheers,
Wendell

Current Thread