Could you please paste all the XSLT code? I think it will be much easier to provide you with a good answer if we can see all of the context. I'm not sure the above approach of using a a for-each loop is the correct choise in your case - but let's see some code so we can guide you :)
Displaying Items the same category as Current Page
Hi there,
I've been trying to solve this one but no luck so far. I would apriciate any help.
My website displays articles, FAQ, books etc.
Every article, FAQ , book etc is asigned to a certain sub-category from a drop down list. They all share the same drop down list.
I need to display in every article page (or book page etc...) a list of related articles which have the same sub-category as the current page.
The site structure is like this:
/ Home
*articles
**** article page (sub-category: red)
**** article page (sub-category: red)
**** article page (sub-category: blue)
*books
**** book page (sub-category: red)
**** book page (sub-category: blue)
**** book page (sub-category: blue)
**** book page (sub-category: green)
Currently, my "for-each" looks like this:
<xsl:for-each select="umbraco.library:GetXmlNodeById(1273)/*/* [@isDoc and string(umbracoNaviHide) != '1' and string(SubCategory) = '1748']">
1748 is a random ID of one of the sub-categories (just something I tried)
how do I add an ecepetion of displaying only items whit the same sub-category?
(Something like and string(SubCategory) = 'same as current page').
Hope my question is clear :)
Thank you for any help!
Yael
Hi Yael
Could you please paste all the XSLT code? I think it will be much easier to provide you with a good answer if we can see all of the context. I'm not sure the above approach of using a a for-each loop is the correct choise in your case - but let's see some code so we can guide you :)
/Jan
Hi Jan,
Here is the code. Hope this would help :)
<?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:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
xmlns:random="urn:random"
exclude-result-prefixes="msxml random umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:param name="MaxNoChars" select="100" />
<xsl:variable name="numberOfItems" select="2"/>
<msxml:script implements-prefix="random" language="C#">
<msxml:assembly name="umbraco"/>
<msxml:using namespace="umbraco"/>
<![CDATA[
public int GetRandom(int minValue, int maxValue)
{
return umbraco.library.GetRandom().Next(minValue, maxValue);
}
]]>
</msxml:script>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:for-each select="umbraco.library:GetXmlNodeById(1273)/*/* [@isDoc and string(umbracoNaviHide) != '1' and string(chooseSubCategory) = '1748']">
<xsl:sort select="random:GetRandom(1, count(umbraco.library:GetXmlNodeById(1273)/*/* [@isDoc and string(umbracoNaviHide) != '1']))" order="ascending" />
<xsl:if test="position() <= $numberOfItems">
<div class="question_box article_box">
<img src="/images/question_box_top.png" alt="question_box_top" />
<div class="question_box_bg_repeat">
<a href="{umbraco.library:NiceUrl(@id)}">
<img class="item_img" src="{./thumb}" alt="" />
</a>
<a href="{umbraco.library:NiceUrl(@id)}"><h3><xsl:value-of select="title" disable-output-escaping="yes"/></h3></a>
<p><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(text), $MaxNoChars, '...')"
disable-output-escaping="yes" /></a></p>
</div>
<a href="{umbraco.library:NiceUrl(@id)}"><img src="/images/box_bottom.png" alt="" /></a>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This code is only for the articles section.
1273 referes to the parent articles node.
1748 is a random sub-category.
Thank you!
Yael
Hi all,
Does anybody know of a way to do this in XSLT? Isn't there a way to refere to a property "same as current page"?
Would really appreciate any help, even if you just tell me that it's not possible in XSLT and I should turn to Razor.
Thanks in advance,
Yael
is working on a reply...
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.