I've got a custom field called relatedProducts in one of my articles. This field can be empty or it can contain a list of IDs (i.e. 4,9,10). I need to execute code similar to the following:
<xsl:for-each select="$currentPage/child::*
[(@parentID = $parentId) and ((contains(current()/relatedProducts,
$productId)) or (string-length($productId) = 0))]"> </xsl:for-each>
The problem is "current()/relatedProducts" doesn't exist at that point in the loop. I can use "current()/relatedProducts" inside the loop to display, but not within the loop parameters. How can I do this comparison?
Inside the loop, current() gives you the current item in the loop - in the select attribute, current() will give you the node that "contains" the for-each, i.e.: if your for-each is inside the "root" template, it'll give you the <macro> element (match="/" is executed on the <macro> element).
I'd write your expression like this:
<xsl:for-each select="
$currentPage/*
[@parentId = $parentId]
[contains(relatedProducts, $productId) or not(normalize-space($productId))]"
>
<!-- do stuff -->
</xsl:for-each>
How do I access custom fields in XSLT loop?
I've got a custom field called relatedProducts in one of my articles. This field can be empty or it can contain a list of IDs (i.e. 4,9,10). I need to execute code similar to the following:
The problem is "current()/relatedProducts" doesn't exist at that point in the loop. I can use "current()/relatedProducts" inside the loop to display, but not within the loop parameters. How can I do this comparison?
Hi Chris,
Inside the loop, current() gives you the current item in the loop - in the select attribute, current() will give you the node that "contains" the for-each, i.e.: if your for-each is inside the "root" template, it'll give you the <macro> element (match="/" is executed on the <macro> element).
I'd write your expression like this:
/Chriztian
is working on a reply...