[xquery-talk] FLWOR in XSLT 2.0?

G. Ken Holman gkholman at CraneSoftwrights.com
Thu Dec 1 07:07:57 PST 2011


At 2011-12-01 15:58 +0100, Geert Josten wrote:
>Funny, I always thought the FLWOR was an XQuery only thing...
>
><xsl:stylesheet version="2.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:b="books">
>  <xsl:output omit-xml-declaration="yes" indent="yes"/>
>  <xsl:strip-space elements="*"/>
>
>  <xsl:template match="/">
>    <xsl:sequence select=
>    "(for $m in max(for $n in distinct-values(/*/b:book/(b:author |
>b:editor)
>                                             /b:name/concat(b:fname, '|',
>b:lname)),
>                    $cnt in count(/*/b:book/(b:author | b:editor)
>                                  /b:name[$n eq concat(b:fname, '|',
>b:lname) ])
>
>...
>
>(Looks quite horrible to me, like someone couldn't decide between XQuery
>and XSLT.. :-/)

Well, in 2.0 it isn't a full FLWOR expression ... no "let", no 
"where" (though this can often be done with a predicate) and no 
"order by".  That is the difference between the XPath "for 
expression" and XQuery "FLWOR expression".

But I have found it useful to say things like:

    <xsl:value-of select="for $each in expr return expr2($each)"/>

or:

    <xsl:apply-templates
      select="for $this in expr1, $that in expr2 return expr3($this, $that)"/>

. . . . . . . .  Ken


--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/t37DVX
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/q/
G. Ken Holman                   mailto:gkholman at CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal



More information about the talk mailing list