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' ">
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>
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')"/>
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>
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']">
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>
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.:
/Chriztian
Thanks for the reply.
I can check like this inside the for loop. But I need the result of hasLogoAndAvailability outside for-each loop.
Hi again - the solution's the same - you just step outside and do the necessary checking:
Hope that helps,
/Chriztian
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
is working on a reply...