xsl-list
[Top] [All Lists]

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

2006-07-17 11:06:30
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.)

One case is a sort based on a lookup field:

<xsl:sort select="$lookup[data=current()/@x]"/>

current() here is a bit of a hack: it's in effect a built-in variable. It
allows you to do a 2-way join without resorting to explicit variables, but
fails when you want a 3-way join:

<xsl:sort select="$lookup1[let $x:=. return data=$lookup2[data=$x/@x]]"/>

In practice I've found that the variable you want to bind here is almost
invariably bound to the context item, which means you can write it as

<xsl:sort select="$lookup1[for $x in . return data=$lookup2[data=$x/@x]]"/>

but it seems an ugly hack to use "for" to iterate over a singleton, just
because you want to bind a variable.

At one time I was trying to come up with some explicit syntax for binding
the context item to a variable, for example

<xsl:sort select="$lookup1[data = with $x do ($lookup2[data=$x/@x])]"/>

but it's not significantly better than using "let $x:=.".

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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>