This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: problem with proper counting


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]