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

counting preceding identical elements

Subject: counting preceding identical elements
From: Steven Noels <stevenn@xxxxxxxxxxxxxxxx>
Date: Fri, 24 Aug 2001 17:21:24 -0500 (CDT)
noels powerpoint
Hi,

I am at loss whether what I am trying to do is at all possible. I would be
able to do it in some other way, but this would mean major rearrangements
to what I have so far, and I would prefer to keep things the way they are.

I am building a simple Powerpoint-style presentation tool running on top
of Cocoon.

My XML-structure is simple:

<presentation>
	<info>...</info>
	<body>
		<section>
			<slide>...</slide>
			<slide>...</slide>
			...
		</section>
		<section>
			yes, same stuff here
			...
		</section>
	</body>
</presentation>

Using Cocoon's clever parameter-passing, I can access each individual
slide using a section and slide number passed through to the stylesheet,
using URL's like
http://localhost/cocoon/presentation/browse?section=2&slide=4

This is all working very nice. Using a main 'presentation' template, I
build the HTML grid and then <xsl:apply-templates
select="body/section[position()=$section]/slide[position()=$slide]"/>.

Outside of the node context created by this template however, I want to
build a little progress indicator showing how far I am in my presentation.

This little portion does most of what I want it to do:


<b><xsl:value-of select="$section"/></b>
<font size="-1"
color="gray">/<xsl:value-of select="count(//section)"/></font>&#160;
<font size="+2"><b>|</b></font>&#160;
<font size="-1"><xsl:value-of select="$slide"/>
	<font color="gray">/
	<xsl:value-of select="count(//section[position()=$section]/slide)"/>
	</font>
</font>

builds up a something like this:

2/ 3  |  4/ 6

which is fine, but only depending on the parameters passed into the
stylesheet ($section and $slide).

The last thing I want to add to the indicator is a percentage - roughly
calculated by dividing the number of preceding slides by the total amount
of slides.

And now I fall into problems because this isn't happening when the context
node 'focus' is on the slide element but outside the main loop.

What I basically try to do is to calculate the number of preceding slide
elements of the slide element which position()=$slide and of which the
parent section element's position()=$section.

But I get all kinds of odd numbers - can't really figure out what is
wrong in my count() argument.

I've been trying
count(//section[position()=$section]/preceding::sibling[position()=$slide])
to no avail.

Then I switched strategies into abusing <xsl:number> like:
<xsl:number level="any" count="//section[$section]/slide[$slide]"/>
but that made not much sense neither.

A long story to ask whether what I am trying to do is really feasible when
not at the slide element itself but only with the basic knowledge that
there IS a fourth slide in section 2 due to the parameters.

Any ideas?

I know using position() is considered to be bad practice. Punish me :-)

Regards,
</Steven>


 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.