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...
<!-- 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() < 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)}"> learn more > </a> </p> </li> </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)
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)
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 " "> ]>
<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() < 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)}"> learn more >
</a>
</p>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
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:
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
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)
<xsl:if test="position() lt; 5"> must be <xsl:if test="position() < 5">
That did it! Thank's for your help.
Thank Dirk
Just what i needed!
it worked
is working on a reply...