[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: Wed, 21 Feb 2001 14:50:01 +0000
xslt append function
Hi Clark,

> Not a very good example... but then again, I was trying to think of
> a syntax that would allow a node set to be built-up over the course
> of the function, and <exsl:return ... /> does not do this.

I did come up with a use case that I think touches on what you're
talking about here, namely returning the first five nodes in an
alphabetical sort of a node set.

<xsl:variable select="my:first-alphabetically($nodes, 5)" />

Under your scheme I think you would use:

<exsl:function name="my:first-alphabetically">
   <exsl:param name="nodes" />
   <exsl:param name="number" />
   <xsl:for-each select="$nodes">
      <xsl:sort />
      <xsl:if test="position() &lt;= $number">
         <exsl:append select="." />
      </xsl:if>
   </xsl:for-each>
</exsl:function>

Without something like exsl:append, you would need to use a recursive
solution which is longer and uglier, but it could be done:

<exsl:function name="my:first-alphabetically">
   <exsl:param name="nodes" />
   <exsl:param name="number" />
   <xsl:choose>
      <xsl:when test="$number = 1">
         <xsl:for-each select="$nodes">
            <xsl:sort />
            <xsl:if test="position() = 1">
               <exsl:result select="." />
            </xsl:if>
         </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
         <xsl:variable name="first"
                       select="my:first-alphabetically($nodes, 1)" />
         <xsl:variable name="rest"
                       select="$nodes[count(.|$first) != 1]" />
         <exsl:result select="$first |
                              my:first-alphabetically($rest,
                                                      $number - 1)" />
      </xsl:otherwise>
   </xsl:choose>
</exsl:function>

I *think* that if you need to build up a node set gradually then it's
always possible to use a recursive solution to do it, but I could be
wrong.  I'd like to see a use case that couldn't be solved
recursively, so where exsl:append or exsl:reference-of would be
necessary.

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.