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

Re: Designs for XSLT functions (Was: Re: RE: syntax su

Subject: Re: Designs for XSLT functions (Was: Re: RE: syntax sugar for call-template)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Feb 2001 10:03:00 +0000
xsl for each select syntax
Hi Mike,

>> Perhaps xsl:for-each shouldn't be allowed directly within function
>> definitions?  Can anyone come up with a use case where it's helpful to
>> have it?
>
> Saxon allows xsl:for-each with saxon:function, but doesn't allow
> saxon:return within xsl:for-each.

Did you see the use cases that I put forward where it could be
useful?:

---
Firstly, as we know, key() and id() are restricted to finding nodes in
the current tree. If I want to use an extension function that
retrieves keyed nodes in a particular document then I need to be able
to do:

<exsl:function name="my:key">
   <xsl:param name="key-name" />
   <xsl:param name="key-value" />
   <xsl:param name="file-name" />
   <xsl:param name="base-node" select="/" />
   <xsl:for-each select="document($file-name, $base-node)">
      <exsl:result select="key($key-name, $key-value)" />
   </xsl:for-each>
</exsl:function>

Another example is if I want to use the built-in sort algorithms to
find, for example, the first value alphabetically in a node set:

<exsl:function name="my:first-alphabetical">
   <xsl:param name="nodes" />
   <xsl:for-each select="$nodes">
      <xsl:sort />
      <xsl:if test="position() = 1">
         <exsl:result select="." />
      </xsl:if>
   </xsl:for-each>
</exsl:function>
---

What do you think?

> Use case, turning a node-set into a comma-separated list of the
> string-values of the nodes:
>
> xsl:function name="csv"
>   xsl:param name="nodeset"/
>   xsl:variable name="tree"
>     xsl:for-each select="$nodeset"
>       xsl:value-of select="."
>       xsl:if test="position()!=last"
>         ,
>       /xsl:if
>     /xsl:for-each
>   /xsl:variable
>   xsl:return select="string($tree)"/
> /xsl:function

Ahh, but this shows an xsl:for-each within an xsl:variable.  I think
that David Rosenborg agrees that that should be allowed - he's only
objecting to allowing anything but xsl:param, xsl:variable and
exsl:result (or exsl:return) directly within exsl:function.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.