[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: A beef with XSLT Sometimes too complicated

Subject: RE: A beef with XSLT Sometimes too complicated
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 17 Jul 2006 19:05:23 +0100
RE:  A beef with XSLT Sometimes too complicated
> 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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.