Recursive calling of tempalte with dynamic condition
Hi all,
I'm haveing 5 promotion nodes under promotions and using contentPicker i have connected those pages to some other pages in the website.
Now i'm showing 3 promotions in each page. and If i'm in the page to which the contentPicker is directing it should not show that promotion.
How is it possible?
Here is my xslt. This works fine if we are in any other page... but its showing only 2 promotions when the 3rd one dynamically selected is directed to a contentpicker.
Recursive calling of tempalte with dynamic condition
Hi all,
I'm haveing 5 promotion nodes under promotions and using contentPicker i have connected those pages to some other pages in the website.
Now i'm showing 3 promotions in each page. and If i'm in the page to which the contentPicker is directing it should not show that promotion.
How is it possible?
Here is my xslt. This works fine if we are in any other page... but its showing only 2 promotions when the 3rd one dynamically selected is directed to a contentpicker.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:bdk="http://bodenko.com"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml msxsl umbraco.library bdk">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:variable name="maxItems">
<xsl:value-of select="number(3)" />
</xsl:variable>
<msxsl:script language="JavaScript" implements-prefix="bdk">
function Random(r) { return Math.ceil(Math.random()*r); }
</msxsl:script>
<xsl:template match="/">
<div id="promos_sub">
<xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]/descendant-or-self::node[@nodeTypeAlias='Promotion']">
<xsl:sort select="bdk:Random($maxItems)" order="descending" />
<xsl:variable name="pImg" select="string(data[@alias='promoImage'])" />
<xsl:variable name="pURL" select="string(data[@alias='externalURL'])"/>
<xsl:if test="$pImg != ''">
<xsl:if test="position() <= $maxItems">
<xsl:variable name="attracId" select="string(data [@alias='attractionLinked'])" />
<xsl:variable name="useExtURL" select="string(data [@alias='useExternalUrl'])" />
<xsl:choose>
<xsl:when test="$attracId != ''">
<xsl:if test="contains($currentPage/@path,$attracId) = false">
<div>
<xsl:choose>
<xsl:when test="$useExtURL ='1'">
<xsl:choose>
<xsl:when test="$pURL !=''">
<a href="{string(data[@alias='externalURL'])}">
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" /></a>
</xsl:when>
<xsl:otherwise>
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<a href="{umbraco.library:NiceUrl($attracId)}">
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" />
</a>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<div>
<xsl:choose>
<xsl:when test="$useExtURL ='1'">
<xsl:choose>
<xsl:when test="$pURL !=''">
<a href="{string(data[@alias='externalURL'])}">
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" /></a>
</xsl:when>
<xsl:otherwise>
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<img src="{umbraco.library:GetMedia($pImg,'false')/data [@alias='umbracoFile']}" />
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
Hi all,
It was a mistake for logic from my end. we dont need to call template recursively.
what i did is updated the for-each by not reading the one which is mapped to the current page or current page parent.
<xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]/descendant-or-self::node[@nodeTypeAlias='Promotion' and contains($currentPage/@path, string(data [@alias='attractionLinked'])) = false]">
This did the trick for me. :)
is working on a reply...