Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bob Jones 33 posts 54 karma points
    Jan 05, 2012 @ 11:48
    Bob Jones
    0

    Count the child nodes for a thread item

    I am unsure how to go about this, initially I set postCount as a generic property for a thread and incremented this each time a comment was created within the thread but realise this is not ideal (if a comment is deleted, for example).

    So my question is, is there an easy way to get a count of child nodes for a given node and would this be best achieved by using xslt?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 05, 2012 @ 11:59
    Chriztian Steinmeier
    0

    Hi Bob

    You can count anything in XSLT - e.g., to count the childnodes of the currentPage you can do this:

    <xsl:value-of select="count($currentPage/*[@isDoc])" />

    To count all nodes of the document type "BlogComment" below, regardless of hierarchy, just do:

    <xsl:value-of select="count($currentPage//BlogComment)" />

    /Chriztian

  • Bob Jones 33 posts 54 karma points
    Jan 05, 2012 @ 12:08
    Bob Jones
    0

    thanks Chriztian,

    I will keep this answer for reference but as I am displaying the said data in an ASP.NET repeater I have decided to update the post count with 

    parentThread.getProperty("postCount").Value = parentThread.Children.Count();

    for now. Although ideally maybe I could fit your solution into the repeater somehow.. ?

Please Sign in or register to post replies

Write your reply to:

Draft