I am a bit of a newbie when it comes to Umbraco and XLST. I am trying to make a macro that will pull back a list 5 most recently created nodes that have a specific document type. This is what I have so far...
It looks like you've come by some XSLT for the "Legacy Schema" (the format of the stored XML). Since Umbraco 4.5 there's been a much better format, known as "The New Schema", in play. Read more here.
Here's a way to do it:
<?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"
exclude-result-prefixes="msxml umbraco.library"
>
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Grab the root of the current site -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Grab the absolute root -->
<xsl:variable name="absRoot" select="$siteRoot/ancestor::root" />
<!-- Input the documenttype you want here -->
<xsl:variable name="documentTypeAlias" select="'NewsItem'" />
<!-- Number of News Items to display -->
<xsl:variable name="itemsToDisplay" select="5" />
<xsl:template match="/">
<!-- Use the applicaple root variable here ($absRoot to search entire solution, $siteRoot within current site) -->
<xsl:for-each select="$absRoot//*[name() = $documentTypeAlias][not(umbracoNaviHide = 1)]">
<xsl:sort select="@createDate" order="descending" />
<xsl:if test="position() <= $itemsToDisplay">
<div class="news-item">
<div class="news-title"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a></div>
<div class="news-date"><xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'MMMM d, yyyy')" /></div>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Need help getting list nodes by document type
Good afternoon all!
I am a bit of a newbie when it comes to Umbraco and XLST. I am trying to make a macro that will pull back a list 5 most recently created nodes that have a specific document type. This is what I have so far...
I'm not getting any errors, and it's not outputting anything.
Any help would be greatly appriciated!
Hi Hank - welcome to the forums!
It looks like you've come by some XSLT for the "Legacy Schema" (the format of the stored XML). Since Umbraco 4.5 there's been a much better format, known as "The New Schema", in play. Read more here.
Here's a way to do it:
/Chriztian
Thank you so much! It's working like a charm!
is working on a reply...