This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: count with variables?
- To: Resch Martin <m dot resch at techdivision dot com>
- Subject: Re: [xsl] count with variables?
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 9 Aug 2001 17:55:01 +0100
- CC: "Xsl-List (E-Mail)" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <729CE593A2AED1419DC1F3CDFE65EA0902D01C@ahmed.techdivision.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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