Subject: Re: [xsl] counting preceding identical elements From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 27 Aug 2001 12:24:36 -0400 |
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.
Good luck, Wendell
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>  <font size="+2"><b>|</b></font>  <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
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] counting preceding identical , Steven Noels | Thread | [xsl] Tools for XPath debugging, Nalini Jensen |
RE: [xsl] Tutorial, Ali Zolghadri | Date | [xsl] MSXML Script Enable, syntax f, Nathan Zhou |
Month |