Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 25, 2010 @ 14:00
    Bo Damgaard Mortensen
    0

    Loop through two collections

    HI all,

    I'm in a situation where I have to compare a node name in one collection of nodes to a document property type of another set of nodes.

    In pseudo: node/document type property value = NodeInOtherCollection/nodeName { expose data from first node }

    Don't know if that makes any sense? This is the xslt I have now:

    <xsl:template match="/">

      <xsl:variable name="categories" select="$currentPage/ancestor-or-self::*/* [@level=2]/* [@isDoc and string(umbracoNaviHide) != 1]" />
      <xsl:variable name="docs" select="$currentPage/ancestor-or-self::*//DocAlias [@isDoc and string(umbracoNaviHide) != 1]" />
      
    <!-- start writing XSLT -->
      <ul>
        <xsl:for-each select="$categories">
          <xsl:for-each select="$docs">
            <xsl:if test="current()/@nodeName = $docs/memberType">
              
              <li><xsl:value-of select="current()/@nodeName" /></li>
            </xsl:if>
       
      </xsl:for-each>

      </xsl:for-each>
      </ul>  
    </xsl:template>

    I honestly don't know what to put in the if statement and the value-of select=""

    Does anyone know how to do this? :)

    Thanks in advance!

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 25, 2010 @ 14:01
    Bo Damgaard Mortensen
    0

    Should note that I have tested the output of the two variables and the output is right :)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 25, 2010 @ 14:34
    Bo Damgaard Mortensen
    0

    Figured it out myself ;)

    Didn't need a nested loop to do what I wanted. This was all it took:

    <xsl:template match="/">

      <xsl:variable name="categories" select="$currentPage/ancestor-or-self::*/* [@level=2]/* [@isDoc and string(umbracoNaviHide) != 1]" />
      <xsl:variable name="docs" select="$currentPage/ancestor-or-self::*//DocAlias [@isDoc and string(umbracoNaviHide) != 1]" />
      
    <!-- start writing XSLT -->
      <ul>

          <xsl:for-each select="$docs">
            <xsl:if test="current()/partnerType = $categories/@nodeName">
              <li><xsl:value-of select="current()/bodyText" /></li>   
            </xsl:if>
          </xsl:for-each>

      </ul>  
    </xsl:template>

  • Colin Browne 31 posts 52 karma points
    Nov 29, 2010 @ 13:03
    Colin Browne
    0

    Found myself needing to something like this on occasion thats quite an elegant way of doing it i must say.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 01, 2010 @ 13:24
    Bo Damgaard Mortensen
    0

    Glad you could use it, Colin! :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies