|
[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
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() <= @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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








