Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hank Metzger 4 posts 24 karma points
    Mar 06, 2013 @ 20:00
    Hank Metzger
    0

    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...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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"/>

    <!-- 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="/">

    <!-- The fun starts here -->



    <xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">

    <xsl:sort select="@createDate" order="descending"/>
       
        <xsl:if test="position() &lt;= $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>

    I'm not getting any errors, and it's not outputting anything.

     

    Any help would be greatly appriciated!

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Mar 06, 2013 @ 21:12
    Chriztian Steinmeier
    0

    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:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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() &lt;= $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>

    /Chriztian

  • Hank Metzger 4 posts 24 karma points
    Mar 06, 2013 @ 21:16
    Hank Metzger
    0

    Thank you so much! It's working like a charm!

  • 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.

Please Sign in or register to post replies