Copied to clipboard

Flag this post as spam?

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


  • Matias Korn 30 posts 49 karma points
    Apr 02, 2012 @ 09:35
    Matias Korn
    0

    Foreach inside foreach

    Hello everybody, i want to make a foreach inside a  foreach.

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
      <h2 class="presentation-headline"><xsl:value-of select="praesentationsTitel"/></h2>
      <img class="presentation-img" align="right">
        <xsl:attribute name="src">
          <xsl:value-of select="praesentationsBillede"/>
        </xsl:attribute>
      </img>
      <ul class="presentation-list">
        <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/*/*">
          <li><xsl:value-of select="@nodeName"/></li>
        </xsl:for-each>
      </ul>
    </xsl:for-each>

    This is ofcorse because of /*/* selecting ALL the children notes from  all the notes. 

    I want an xpath something like this:

    umbraco.library:GetXmlNodeById($source)/[select current foreach item]/*

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 02, 2012 @ 11:02
    Lee Kelleher
    0

    Hi Matias,

    Inside the "select" for your second (nested) for-each loop, you don't need the "umbraco.library:GetXmlNodeById" function.

    Try this instead:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/*[@isDoc and string(umbracoNaviHide) != '1']">
      <h2 class="presentation-headline"><xsl:value-of select="praesentationsTitel"/></h2>
      <img class="presentation-img" align="right">
        <xsl:attribute name="src">
          <xsl:value-of select="praesentationsBillede"/>
        </xsl:attribute>
      </img>
      <ul class="presentation-list">
        <xsl:for-each select="*[@isDoc and string(umbracoNaviHide) != '1']">
          <li><xsl:value-of select="@nodeName"/></li>
        </xsl:for-each>
      </ul>
    </xsl:for-each>

    Cheers, Lee.

  • Matias Korn 30 posts 49 karma points
    Apr 02, 2012 @ 11:11
    Matias Korn
    0

    thank you, didn't knew you could "continue" xpath with an * :) nice thanks you.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 02, 2012 @ 11:35
    Lee Kelleher
    0

    Hi Matias,

    Yes, once you are inside the for-each loop, you have the context of the current node... so any XPath used will be applied against that. :-)

    Cheers, Lee.

  • 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