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

Re: There must be a better way

Subject: Re: There must be a better way
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 5 Oct 2001 10:09:39 -0400
href the better way
If you want "efficiency", then you should not compute anything that can be
pre-computed.  So you shouldn't use //CHAPTER[last()] over and over again.
Make it a variable.  It's especially worth doing because "//" tends to be
slow, especially with some processors.

Then you could create a key that returns the chapter when you give it a part
number, and use that key in any tests.  This way you could avoid using
//CHAPTER[number($partNo)] repeatedly.

Next you could make a template that tests whether a chapter is the last
chapter and call that template when you want to find out.  That way, any
improvements you think up would be easier to incorporate.  You could put the
xsl:if test in that template, making the main line of the code cleaner and
easier to follow.

Then, you don't need


You can just use .html

On the other hand, if the code executes fast enough already, you could just
leave it alone...


Tom P

[Nicholas Waltham]

>  I am trying to build a set of links (outputting to HTML) based on what
> chapter a named template is called from.
> I have come up with this:
> <xsl:template name="TopLinks">
> <a href="{$prefix}.html"><img src="toc.gif" alt="Table of Contents"
> border="0"/></a>
> <xsl:variable name="partNo"><xsl:number level="single"
> count="CHAPTER"/></xsl:variable>
> <xsl:variable name="prev" ><xsl:value-of select="$prefix"/><xsl:value-of
> select="number($partNo)-1"/><xsl:text>.html</xsl:text></xsl:variable>
> <xsl:variable name="next" ><xsl:value-of select="$prefix"/><xsl:value-of
> select="number($partNo)+1"/><xsl:text>.html</xsl:text></xsl:variable>
> <xsl:if test="number($partNo)>1">
> <a href="{$prev}"><img src="back.GIF" alt="Previous" border="0"/></a>
> </xsl:if>
> <xsl:if test="not(//CHAPTER[number($partNo)]=//CHAPTER[last()])">
> <a href="{$next}"><img src="next.GIF" alt="Next" border="0"/></a>
> </xsl:if>
> </xsl:template>
> It does work, however, it strikes me that it is not really very efficient.
> Particularly the bottom piece for detecting if I
> am in the last chapter. Could anyway offer me suggestions on how I could
> improve this. $prefix is a parameter, and
> the named template is called from another template which  matches any
> <CHAPTER> element.

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

Current Thread


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