Copied to clipboard

Flag this post as spam?

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


  • Jan Vermeerbergen 79 posts 112 karma points
    Dec 09, 2011 @ 01:49
    Jan Vermeerbergen
    0

    How to do Foreach for nodes which have subnodes?

    I'm going crazy over (what appears to me) a simple for-each loop:

    I need a for-each of categories, but only categories that have products underneath them.

    I can't check for childnodes within the loop, since I am using position() to but a line break after every third category. (if position() mod 3 = 0 .....)

    Anybody? 

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 09, 2011 @ 08:21
    Chriztian Steinmeier
    0

    Hi Jan,

    You should put that requirement in the select attribute of your for-each:

    <xsl:for-each select="$categoryRoot/*[@isDoc][*[@isDoc]]">

    It looks a llittle bit worse than it actually is - $categoryRoot is of course the parentnode of your categories - /*[@isDoc] takes all Document children of that parentnode; [*[@isDoc]] is the requirement you're after, since it means that the nodes selected by the previous part, must also have child Document nodes.

    If your "category" nodes has the Document Type alias "Category", you can make it more readable by using that instead:

     <xsl:for-each select="$categoryRoot/Category[Category]"> 

    - much better, right?

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft