Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Sep 02, 2009 @ 05:07
    Amir Khan
    0

    Sort order and limit of child nodes.

    I have this xlst which gives 4 childnodes of a define parent, the sort order is descending, how do i make it so it gets the last 4 instead of the 1st 6 then stopping?

    Like lets say i have 8 pages, it seems to be listing 4,3,2,1 instead of 8,7,6,5...

    Thank you!

    <?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" 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"/>

    <!-- Don't change this, but add a 'contentPicker' element to -->
    <!-- your macro with an alias named 'source' -->
    <xsl:variable name="source" select="1155"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1' and position() &lt; 5]">
                <xsl:sort select="@sortOrder" data-type="number" order="descending" />
        <li>
            <h3><xsl:value-of select="data[@alias= 'date']" /></h3>
            <p>
            <xsl:value-of select="@nodeName"/>
            <a href="{umbraco.library:NiceUrl(@id)}">&nbsp;learn more&nbsp;&gt;                     
            </a>
            </p>   
        </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 02, 2009 @ 08:38
    Dirk De Grave
    1

    Hi Amir,

     

    You'll have to move the 'position()' logic out of the for-each loop and use it in an if statement as in:

    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']">
                <xsl:sort select="@sortOrder" data-type="number" order="descending" />
        <xsl:if test="position() lt; 5">
        <li>
            <h3><xsl:value-of select="data[@alias= 'date']" /></h3>
            <p>
            <xsl:value-of select="@nodeName"/>
            <a href="{umbraco.library:NiceUrl(@id)}">&nbsp;learn more&nbsp;&gt;                      
            </a>
            </p>    
        </li>
        </xsl:if>
    </xsl:for-each>
    </ul>

    In your example, you created a list of 4 nodes and then perform the sorting (as this is forward only reading, only the first 4 nodes 1,2,3,4 were taken into account when performing the sort resulting in 4,3,2,1)

     

    Cheers,

    /Dirk

     

  • Amir Khan 1287 posts 2744 karma points
    Sep 09, 2009 @ 16:55
    Amir Khan
    0

    hmm, I'm getting the following error when i try your solutin, any thoughts?

     

    Error occured

    System.Xml.Xsl.XslLoadException: Expected end of the expression, found 'lt'.
    position() -->lt<-- ; 5 An error occurred at C:\Websites\test.centracomm.net\xslt\633880905255737785_temp.xslt(24,1).
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • Ron Brouwer 273 posts 768 karma points
    Sep 09, 2009 @ 16:58
    Ron Brouwer
    1

    <xsl:if test="position() lt; 5"> must be <xsl:if test="position() &lt; 5">

  • Amir Khan 1287 posts 2744 karma points
    Sep 15, 2009 @ 02:27
    Amir Khan
    0

    That did it! Thank's for your help.

  • MartinB 411 posts 512 karma points
    Aug 14, 2010 @ 00:53
    MartinB
    0

    Thank Dirk

    Just what i needed!

  • Arlan 58 posts 184 karma points
    Feb 16, 2015 @ 19:20
    Arlan
    0

    it worked

Please Sign in or register to post replies

Write your reply to:

Draft