This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
There must be a better way
- To: "xsl-list" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] There must be a better way
- From: "Nicholas Waltham" <info at nwaltham dot com>
- Date: Fri, 5 Oct 2001 10:59:18 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi All,
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.
Thanks,
Nicholas Waltham
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list