This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Re: [docbook-apps] Page X of Y in user.footer.navigation
- From: "Bob Stayton" <bobs at sagehill dot net>
- To: "Diane Larin" <diane at inro dot ca>, <docbook-apps at lists dot oasis-open dot org>
- Date: Fri, 1 Apr 2005 01:32:55 -0800
- Subject: Re: [docbook-apps] Page X of Y in user.footer.navigation
- References: <200504010032.j310WlR26045@cocoa.inro.ca>
Well, I never know how much information to give because list participants
have a wide range of experience with XSL. 8^)
Here is a sample customization of 'user.footer.content'. The first three
variables are global (not inside a template), so they are computed once when
the stylesheet starts.
<!-- Create the chunk hierarchy -->
<xsl:variable name="mychunk.hierarchy">
<xsl:if test="function-available('exsl:node-set')">
<xsl:message>Computing chunks...</xsl:message>
<xsl:apply-templates select="/*" mode="find.chunks"/>
</xsl:if>
</xsl:variable>
<!-- Turn the chunk hierarchy into a node-set -->
<xsl:variable name="mychunks"
select="exsl:node-set($mychunk.hierarchy)//div"/>
<!-- Get the total number of chunks -->
<xsl:variable name="chunk.total" select="count($mychunks)"/>
<!-- Add a line to the footer -->
<xsl:template name="user.footer.content">
<!-- Get the id of the current chunk -->
<xsl:variable name="genid" select="generate-id()"/>
<!-- Get the position of the current chunk.
You have to switch contexts using xsl:for-each to
get the position within the node-set. -->
<xsl:variable name="X">
<xsl:for-each select="$mychunks">
<xsl:if test="@id = $genid">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- Output the numbers -->
<div class="nodecount">
<xsl:text>Node </xsl:text>
<xsl:value-of select="$X"/>
<xsl:text> of </xsl:text>
<xsl:value-of select="$chunk.total"/>
</div>
</xsl:template>
I originally thought iterating over all the chunks using xsl:for-each would
slow things down, since it is done for each chunk. But my tests show it
doesn't affect processing time much, even for a 400 chunk document.
Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net
----- Original Message -----
From: "Diane Larin" <diane@inro.ca>
To: <docbook-apps@lists.oasis-open.org>
Sent: Thursday, March 31, 2005 4:32 PM
Subject: Re: [docbook-apps] Page X of Y in user.footer.navigation
> I had a look at the 'process-chunk-element' template but I find
> it quite cryptic (I don't have a lot of experience in writing/modifying
> XSL stylesheets). I was expecting that I was not the first one to have
> this need and that a "recipe" would exist :-(
>
> Diane Larin
> INRO
>
> On Wed, 30 Mar 2005, Bob Stayton wrote:
>
> > I think this could be done by borrowing some of the chunkfast code.
> It
> > precomputes a node-set of all the chunks. Once you have that, you
> could
> > count the nodes to get Y, and figure out the position of the current
> chunk
> > in the node-set to get X. Take a look at the first part of the
> template
> > named 'process-chunk-element' in html/chunk-code.xsl. It shows how to
> > process nodes in the chunk node-set.
> >
> > Bob Stayton
> > Sagehill Enterprises
> > DocBook Consulting
> > bobs@sagehill.net
> >
> >
> > ----- Original Message -----
> > From: "Diane Larin" <diane@inro.ca>
> > To: <bobs@sagehill.net>
> > Cc: <diane@inro.ca>
> > Sent: Wednesday, March 30, 2005 7:06 AM
> > Subject: Re: [docbook-apps] Page X of Y in user.footer.navigation
> >
> >
> > > > I'm not sure I understand. There are no page numbers in chunked
> HTML.
> > > > Do you mean to label the chunks with a sequence number X, with Y
> being
> > > > the total number of chunks?
> > >
> > > Exactly. This is for a tutorial where we want to be able to inform
> > > the user what remains to be done.
> > >
> > > Diane Larin
> > > INRO
>
>
>