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

Re: Efficient Recursive Algorithms in XSLT (Was: Re: C

Subject: Re: Efficient Recursive Algorithms in XSLT (Was: Re: Constructing X number of elements)
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Aug 2001 13:32:44 -0400
star.gif
With respect,

We've given Ilkka the simple recursive solution. And Dimitre has reminded us that in the general case, there are also better approaches. But Ilkka's problem may not need to be solved in the general case.

For example, let's assume there will never be more than five stars.

<my:stars> <!-- you'll need to have declared the 'my' namespace -->
  <img src="star.gif" alt="first star"/>
  <img src="star.gif" alt="second star"/>
  <img src="star.gif" alt="third star"/>
  <img src="star.gif" alt="fourth star"/>
  <img src="star.gif" alt="fifth star"/>
</my:stars>

<xsl:variable name="stars" select="document('')/*/my:stars/img"/>

Then,
<xsl:template match="movie">
  ...
  <xsl:copy-of select="$stars[position() &lt;= @rating]" />
  ...
</xsl:template>

This is neat, efficient, does not rely on recursion with its ungainliness and potential performance hit (as if that were likely to be a problem at five levels), and is easily extended to handle, say, a maximum of seven or nine stars. The stars can even be different.

It's a refinement of Chris's solution.

Cheers,
Wendell

At 10:42 AM 8/21/01, Dimitre wrote:
This solution will crash some XSLT processors and is generally less efficient (both
in time and space) than another general approach for implementing recursive
algorithms....



====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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.