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

RE: problem with proper counting

Subject: RE: problem with proper counting
From: "Chris Bayes" <chris@xxxxxxxxxxx>
Date: Wed, 24 Oct 2001 09:31:06 +0100
counting bayes
Andreas,
Beginners rule #1. Don't use xsl:for-each.
The following stylesheet gives examples of what you want.
<xsl:template match="page">
	<p>
		<a>
			<xsl:attribute name="name"><xsl:number
level="multiple" format="1-1" count="page|set"/></xsl:attribute>
			<xsl:value-of select="@id" />
		</a>
		<a>
			<xsl:attribute name="href">#<xsl:call-template
name="prep" /></xsl:attribute>
			Previous Page
		</a>
		<a>
			<xsl:attribute name="href">#<xsl:call-template
name="nexp" /></xsl:attribute>
			Next Page
		</a>
	</p>
</xsl:template>
<xsl:template name="prep">
	<xsl:param name="e" />
	<xsl:for-each select="preceding::page[1]">
		<xsl:number level="multiple" format="1-1"
count="page|set"/>
	</xsl:for-each>
</xsl:template>
<xsl:template name="nexp">
	<xsl:param name="e" />
	<xsl:for-each select="following::page[1]">
		<xsl:number level="multiple" format="1-1"
count="page|set"/>
	</xsl:for-each>
</xsl:template>

Notice that I do use xsl:for-each so you might think that I am
contradicting beginners rule #1 but I'm not exactly. Rule #1 states in
section 2 that xsl:for-each is mainly used to change context. That is
what I am doing here. Xsl:number calculates the result from the current
element. When the template prep is called the for-each selects the first
preceding page element so that xsl:number calculates it's result from
the context of the preceding page element. The same for nexp but using
the context of the following page element.

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/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.