You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mariusz Nowostawski <ma...@marni.otago.ac.nz> on 2000/06/12 05:45:19 UTC

[xslt] element counting

Sorry for being slightly off topic here, but is there any other way to
count (get the number of) particular children of a given element other
than iterating through those children and grabing the last element
position()?

At the moment I am doing:

<xsl:for-each select="someTag">
   <xsl:if test="position()=last()">
     do smth with <xsl:value-of select="position()"/>
   </xsl:if>
</xsl:for-each>

but it seems to me kind of way around. 
I do not know how to build expression which returns the position of the
last "someTag" element, is it possible?
I have read about <xsl:number>, but I could not make it to work either in
this case, I do not want to "iterate", I just want the total number.

Any suggestions?

--
Mariusz


Re: [xslt] element counting

Posted by Steve A Drake <sa...@comet.ucar.edu>.
On Mon, 12 Jun 2000, Uli Mayring wrote:

> On Mon, 12 Jun 2000, Alexander Goller wrote:
> 
> > 
> > 
> > 
> > Hi,
> > 
> > On Mon, Jun 12, 2000 at 07:34:53AM -0500, Wang, gonghui wrote:
> > > try count(soneTag), it seems to work
> > 
> > If i'm not mistaken last() returns the number of the last Element
> > already.
> 
> Does it not return the last element itself? Of course you could do
> position(last()) ;-)

If you use "count" you might also want to use "from" to define the node 
where you start counting. You could use something like:

<xsl:number count="bar" from="foo" />

There's a nice XSL FAQ at
http://freespace.virgin.net/b.pawson/xsl/xslfaq.html


Re: [xslt] element counting

Posted by Uli Mayring <ul...@denic.de>.
On Mon, 12 Jun 2000, Alexander Goller wrote:

> 
> 
> 
> Hi,
> 
> On Mon, Jun 12, 2000 at 07:34:53AM -0500, Wang, gonghui wrote:
> > try count(soneTag), it seems to work
> 
> If i'm not mistaken last() returns the number of the last Element
> already.

Does it not return the last element itself? Of course you could do
position(last()) ;-)

Ulrich

-- 
Ulrich Mayring
DENIC eG, Softwareentwicklung


Re: [xslt] element counting

Posted by Alexander Goller <al...@vivien.franken.de>.
Hi, 

On Mon, Jun 12, 2000 at 07:34:53AM -0500, Wang, gonghui wrote:
> try count(soneTag), it seems to work

If i'm not mistaken last() returns the number of the last Element
already. 

bye, alex
-- 
alexander goller		alex@vivien.franken.de

Re: [xslt] element counting

Posted by "Wang, gonghui" <gw...@houston.geoquest.slb.com>.
try count(soneTag), it seems to work

Mariusz Nowostawski wrote:

> Sorry for being slightly off topic here, but is there any other way to
> count (get the number of) particular children of a given element other
> than iterating through those children and grabing the last element
> position()?
>
> At the moment I am doing:
>
> <xsl:for-each select="someTag">
>    <xsl:if test="position()=last()">
>      do smth with <xsl:value-of select="position()"/>
>    </xsl:if>
> </xsl:for-each>
>
> but it seems to me kind of way around.
> I do not know how to build expression which returns the position of the
> last "someTag" element, is it possible?
> I have read about <xsl:number>, but I could not make it to work either in
> this case, I do not want to "iterate", I just want the total number.
>
> Any suggestions?
>
> --
> Mariusz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: [xslt] element counting

Posted by Matthew Cordes <mc...@maine.edu>.
Mariusz,

Try the XPath count( <node-set> ) function.  I think this will do what 
you want.  It is described in section 4.1 of the latest XPath spec or 
page 434 of "XSLT Programmer's Reference" by Michael Kay.

( This is slightly off topic, you might wanna try www.mulberrytech.com's
list dedicated to XSLT or grab Kay's book, I highly recommend it. )

-matt


On Mon, Jun 12, 2000 at 03:45:19PM +1200, Mariusz Nowostawski wrote:
> Sorry for being slightly off topic here, but is there any other way to
> count (get the number of) particular children of a given element other
> than iterating through those children and grabing the last element
> position()?
> 
> At the moment I am doing:
> 
> <xsl:for-each select="someTag">
>    <xsl:if test="position()=last()">
>      do smth with <xsl:value-of select="position()"/>
>    </xsl:if>
> </xsl:for-each>
> 
> but it seems to me kind of way around. 
> I do not know how to build expression which returns the position of the
> last "someTag" element, is it possible?
> I have read about <xsl:number>, but I could not make it to work either in
> this case, I do not want to "iterate", I just want the total number.
> 
> Any suggestions?
> 
> --
> Mariusz
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>