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

Re: count with variables?

Subject: Re: count with variables?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 9 Aug 2001 17:55:01 +0100
select count variable
Hi Resch,

> the nodes <fragmentX> don´t have allways the same name, but in node
> <status> and <sub-root> they have, so i read the name and put it
> into a variable called $actuall_name. that´s ok, and now i want to
> count these nodes under <sub-root> and give the result to an other
> varible called $actuall_result.

I'm a bit confused because the fragmentX elements that you show in the
sample XML are all children of sub-sub-root rather than sub-root.

Anyway, you need to find the elements that have the same name as is
held in the $actuall_name variable. If you're on the parent of these
elements, then you can find them by collecting all the elements and
filtering in those whose name() is equal to $actuall_name:

  *[name() = $actuall_name]

So I think you want either:

  <xsl:variable name="actuall_result"
                select="count(root/sub-root/sub-sub-root
                                /*[name() = $actuall_name])" />

or possibly:

  <xsl:variable name="actuall_result"
                select="count(root/sub-root//*[name() =
                                               $actuall_name])" />

> i´ve tried something like
> <xsl:value-of select="count(../..[$actuall_name])"/>  or
> <xsl:value-of select="count(root/sub-root[$actuall_name])"/>
> but nothing is correct. 

Just to clarify why these don't work. In both of these, you're using
$actuall_name directly in a predicate. Predicates filter in particular
nodes when their contents evaluates as true. If $actuall_name has any
characters in it (which it will do) then it will always evaluate as
true, so the predicate is effectively doing nothing and you may as
well be doing:

<xsl:value-of select="count(../..)" />
<xsl:value-of select="count(root/sub-root)" />

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.