|
|
Rank: Newbie
Joined: 9/9/2008 Posts: 18 Location: India
|
Hi,
How to find out no.of records in XSLT under a particular node
i used count(*). But its not giving the right count.
Please help me
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Hi manuraidu, Count() function is perfect, but the arg is not ok (As you've already figured out). Here's a code snippet that has a count() function in it (It is counting the nodes that are childs of the $currentPage Code:<xsl:value-of select="count($currentPage/node)"/> Key here is, that count() function is expecting a 'node set' parameter. Another example: Code:<xsl:for-each select="$currentPage/node"> <xsl:if test="count(current()/node) > 0"> ...blahblad </xsl:if> </xsl:for-each>
which counts child nodes that are childs of the current node you're processing. Hope that helps. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Newbie
Joined: 10/1/2008 Posts: 10 Location: Sweden
|
I´have a similiare problem. But I want to count nodes at a specified level from a parent node. Is this possible in Umbraco?
|
|
Rank: Enthusiast
Joined: 5/6/2008 Posts: 38 Location: Philippines
|
All you need is something like this: $currentPage/ancestor-or-self::node [@level=1] Where level is an intiger. The command is basically give me all nodes at this level deep ([@level=X]) with X being your specified level.
"Nothing is Impossible" -Umbraco Boracay Packages, Makati, Manila Office Space
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Hi, Of course it is, that's plain xpath stuff. All you need need is the xpath query that counts the nodes for a specified level. Code:<xsl:value-of select="count(umbraco.library:GetXmlById(1043)/node [@level = 2])" /> Of course, you could replace the 1043 (Probably the id of the root node...) and 2 by params/variables. Eg. those can be retrieved from the macro properties. Depends on the context. Hope that helps. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
mcculla10 wrote:All you need is something like this: $currentPage/ancestor-or-self::node [@level=1]
-> Only selects nodes that are 'direct' parents... result of the statement is always 0 or 1?
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Newbie
Joined: 10/1/2008 Posts: 10 Location: Sweden
|
well I have tried these methods but they do not work like I want. I´m trying to count the child nodes from DateFolder mapstructure. Like this: Code: News - 2008 - 10 - 15 - NewsItem - NewsItem - 14 - NewsItem - NewsItem - NewsItem - NewsItem
As you can see in this example I want to count all the NewsItems from month 10. So I can show the number of news that exist for every month.
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Hi, Add another constraint on the xpath query... Code:@nodeTypeAlias='NewsItem' Replace NewsItem with the alias of the nodes 'NewsItem'. Hope that helps. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
|
Guest |