I'm fairly new to Umbraco and XSLT having only been using them for a personal project since June. I've found the forums and wiki an excellent source of help and until now haven't needed to post anything here. But I am now completely stuck and wonder if any of you could help me. I've got an XSLT macro I have created for my site to populate a "Things you may also like" sort of section on my site.
To give you some background, my site is basically editorial content made up of Articles and Reviews. I want to populate this "you may also like" section with the 5 most recently posted Articles and Reviews, but NOT if one of those is the article or review the user is currently reading. I hope that makes sense! I've been trying to do it on articleTitle or reviewTitle (properties on the document types) but I'm getting nowhere. Here is the XSLT I have at the moment which almost does what I want. It lists the 5 most recent posts to the site but even if one of those is the page they are currently reading. I've also put in a commented out line that almost worked but not quite. Doing this did remove the article or review currently being read, but also limited the list to just articles or just reviews and I want it to combine both. I really hope this makes sense but feel free to ask as many questions as you need to! Thanks in advance :)
Thank you so much for your quick response. That has worked perfectly! I thought I may need to do something with the @id and break the logic down but I was struggling with my limited knowledge! I understand what you've done and I think I can probably go and clean up some of my other XSLT macros now!
Checking a document property in for-each
Hi guys,
I'm fairly new to Umbraco and XSLT having only been using them for a personal project since June. I've found the forums and wiki an excellent source of help and until now haven't needed to post anything here. But I am now completely stuck and wonder if any of you could help me. I've got an XSLT macro I have created for my site to populate a "Things you may also like" sort of section on my site.
To give you some background, my site is basically editorial content made up of Articles and Reviews. I want to populate this "you may also like" section with the 5 most recently posted Articles and Reviews, but NOT if one of those is the article or review the user is currently reading. I hope that makes sense! I've been trying to do it on articleTitle or reviewTitle (properties on the document types) but I'm getting nowhere. Here is the XSLT I have at the moment which almost does what I want. It lists the 5 most recent posts to the site but even if one of those is the page they are currently reading. I've also put in a commented out line that almost worked but not quite. Doing this did remove the article or review currently being read, but also limited the list to just articles or just reviews and I want it to combine both. I really hope this makes sense but feel free to ask as many questions as you need to! Thanks in advance :)
<?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"
exclude-result-prefixes="msxml 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:variable name="articleTypeAlias" select="string('Article')"/>
<xsl:variable name="reviewTypeAlias" select="string('Review')"/>
<xsl:variable name="maxRecentPublished" select="5" />
<xsl:variable name="root" select="$currentPage/ancestor-or-self::Homepage" />
<xsl:template match="/">
<!-- The fun starts here -->
<!-- <xsl:for-each select="$root/*[@isDoc]/* [name() = $articleTypeAlias and $currentPage/articleTitle != articleTitle or name() = $reviewTypeAlias and $currentPage/reviewTitle != reviewTitle and @isDoc and string(umbracoNaviHide) != '1']"> -->
<xsl:for-each select="$root/*[@isDoc]/* [name() = $articleTypeAlias or name() = $reviewTypeAlias and @isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="publishedDate" order="descending"/>
<xsl:if test="position() <= $maxRecentPublished">
<xsl:if test="name() = $articleTypeAlias">
<hr width="80%" colour="#D3D3D3"></hr>
<a href="{umbraco.library:NiceUrl(@id)}" class="youMayAlsoTitle">
<xsl:value-of select="articleTitle"/>
</a>
</xsl:if>
<xsl:if test="name() = $reviewTypeAlias">
<hr width="80%" colour="#D3D3D3"></hr>
<a href="{umbraco.library:NiceUrl(@id)}" class="youMayAlsoTitle">
<xsl:value-of select="reviewTitle"/>
</a>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hi Sarah,
Here's a way to do that - I've rearranged some bits and pieces, but hopefully it's pretty easy to understand what's going on - otherwise just ask!
/Chriztian
Hi Chriztian,
Thank you so much for your quick response. That has worked perfectly! I thought I may need to do something with the @id and break the logic down but I was struggling with my limited knowledge! I understand what you've done and I think I can probably go and clean up some of my other XSLT macros now!
Thanks again :)
Sarah
is working on a reply...