Copied to clipboard

Flag this post as spam?

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


  • Anju 12 posts 32 karma points
    Sep 17, 2014 @ 11:24
    Anju
    0

    Check whether the for loop executes in XSLT

    Hi,

    I would like to check whether the "if" condition executes inside the for loop of XSLT code. I can't able to assign varaibles there. Please help me ASAP.

     

     <xsl:for-each select="$currentPage/child::*[@isDoc and name() = 'Brand' and string(umbracoNaviHide) != '1']">

               <xsl:if test = "brandLogo != '' and ($ProductAvailability ='' or ($ProductAvailability='In-Store' ">

              </xsl:if>

    </xsl:for-each>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 17, 2014 @ 11:39
    Chriztian Steinmeier
    0

    Hi Anju

    Well, if it executes, it will continue inside with whatever you do in there - if you need to know about it "outside" - perform the comparison outside, e.g.:

    <xsl:for-each select="$currentPage/Brand[not(umbracoNaviHide = 1)]">
        <!-- Perform the check(s) -->
        <xsl:variable name="hasLogoAndAvailability" select="normalize-space(brandLogo) and (not(normalize-space($ProductAvailability)) or $ProductAvailability = 'In-Store')" />
    
        <!-- Test -->
        <xsl:if test="$hasLogoAndAvailability">
            <!-- do stuff -->
        </xsl:if>
    
        <!-- do more stuff -->
    
        <!-- Another test -->
        <xsl:if test="$hasLogoAndAvailability">
            <!-- do stuff -->
        </xsl:if>
    </xsl:for-each>
    

    /Chriztian

  • Anju 12 posts 32 karma points
    Sep 17, 2014 @ 12:10
    Anju
    0

    Thanks for the reply.

    I can check like this inside the for loop. But I need the result of hasLogoAndAvailability outside for-each loop.

    <xsl:variablename="hasLogoAndAvailability"select="normalize-space(brandLogo) and (not(normalize-space($ProductAvailability)) or $ProductAvailability = 'In-Store')"/>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 17, 2014 @ 13:11
    Chriztian Steinmeier
    0

    Hi again - the solution's the same - you just step outside and do the necessary checking:

    <xsl:variable name="availableBrands" select="$currentPage/Brand[not(umbracoNaviHide = 1)]" />
    <xsl:variable name="brandsWithAvailability" select="$availableBrands[normalize-space(brandLogo) and (not(normalize-space($ProductAvailability)) or $ProductAvailability = 'In-Store')]" />
    
    <xsl:for-each select="$brandsWithAvailability">
        <!-- do stuff with them -->
    </xsl:for-each>
    
    <xsl:if test="$brandsWithAvailability">
        <!-- do some more if there were output earlier -->
    </xsl:if>
    

    Hope that helps,

    /Chriztian

  • Anju 12 posts 32 karma points
    Sep 18, 2014 @ 07:02
    Anju
    0

    Thanks Chriztian.

    I have changed the code based on the way you mentioned. We need to iterate all nodes with type "brand". The issue with this code is we are getting all brands in "availableBrands". But while entering in foreach loop, we are getting the first record only.Since we are assinging 'brandAvail' variable outside the foreach loop, that value is not changing.'brandAvail' is based on the 'availableBrands'. So I can't able to proceed with that way.

     Our actual requirement is we need to show a content if it satisfies the "if condition". If  there is no record to display,we need to show another content outside for loop. 

     

     

      <xsl:variable name="availableBrands" select="$currentPage/child::*[@isDoc and name() = 'Brand' and string(umbracoNaviHide) != '1']" />

    <xsl:variable name="brandAvail" select ="$availableBrands[normalize-space(brandLogo)] and ($ProductAvailability ='' or ($ProductAvailability='In-Store' and  contains($inStoreBrands,@id)) or ($ProductAvailability ='Online' and  contains(brandAvailability, $ProductAvailability)))  and contains(productTypes, $ProductType)  and (string($Branch) = '' or contains($BranchNode,$availableBrands/@id))"/>

    <xsl:for-each select="$currentPage/child::*[@isDoc and name() = 'Brand' and string(umbracoNaviHide) != '1']">

      <xsl:if test = "$brandAvail='true'">

        <div>

        </div>

      </xsl:if>

    </xsl:for-each>

     

     

    Please help ASAP.

     

    Thanks in advance

    Anju

Please Sign in or register to post replies

Write your reply to:

Draft