Copied to clipboard

Flag this post as spam?

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


  • Jim 18 posts 36 karma points
    May 31, 2011 @ 10:34
    Jim
    0

    xslt not giving correct count response

    I have the following xslt expression

    <xsl:variable name="itemCount" select="count($currentPage/ancestor::root/PageBanners/*)"></xsl:variable>

     

    My understanding of this is as follows:


    From the current page, go up until you hit the root, then go one level down to a node type of PageBanners and then count all the immediate children of this node.

     

    This returns a count of 5 when there are only 3 children.

    This really confuses me, I have tried re-publishing the entire site, still says there are 5 children.

    If I change the select statement to the following it returns a count of 3, PageBanner is the only type allowed under the PageBanners node and only has 3 items in.

    <xsl:variable name="itemCount" select="count($currentPage/ancestor::root/PageBanners/PageBanner)"></xsl:variable>

    Can someone please explain why my initial statement is returning a count of 5??

     

    Thanks in advance.

    Jim

  • Daniel Bardi 927 posts 2562 karma points
    May 31, 2011 @ 11:37
    Daniel Bardi
    0

    First one is counting root node and PageBanners node along with each pagebanner node due to *

  • Jim 18 posts 36 karma points
    May 31, 2011 @ 11:41
    Jim
    0

    I thought it might be doing something like that but thought that would be wrong....

    Surely if you used that statement in a foreach, you would only iterate 3 times, not 5??

     

     

  • Sean Holmesby 61 posts 82 karma points
    Jun 02, 2011 @ 00:55
    Sean Holmesby
    0

    Can you try count($currentPage/ancestor::root/PageBanners/*[@isDoc])?

    It could be counting the fields within the nodes, and not just the nodes themselves. I could be wrong though, so it may be worth a test. 

Please Sign in or register to post replies

Write your reply to:

Draft