Can you try something like this, am not sure how you are accessing your folder containing your newsitems. So am just try get it by using the GetXmlNodeById.
<!-- Don't change this, but add a 'contentPicker' element to --> <!-- your macro with an alias named 'source' --> <xsl:variable name="source" select="1200"/> <!-- enter parent NodeId --> <xsl:variable name="newsitems" select="4"/> <xsl:variable name="numberOfItems" select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1'])"/> <xsl:variable name="jump" select="$itemsToDisplay * $pageNumber" />
I made the Xslt from the std. "List subpages from a changeable source", setup "source" in the macro, and added the macro to the template selecting the parent (id 1107) of my news items.
If i insert all of your code and change the parent node to "1107" i get the following error:
Error occured
System.Xml.Xsl.XslLoadException: The variable or parameter 'itemsToDisplay' is either not defined or it is out of scope.
With the above code, the paging is working correct, from what i can see... If i have say 6 newsitems and set "newsitems" to "1" paging generates "1 2 3 4 5 6" and "next"... But there is something about the "Output ..."
If newsitems = 4, paging will correctly be " 1 2 next" but the output shold be 4 x "Output ..." on page 1 and on page 2 "Output ..." only shows up once (should be twice).
Do i need another "<xsl:for-each..." around "Output..." in the code below or is it something completely else, that im not getting?
With the above code, the paging is working correct, from what i can see... If i have say 6 newsitems and set "newsitems" to "1" paging generates "1 2 3 4 5 6" and "next"... But there is something about the "Output ..."
If newsitems = 4, paging will correctly be " 1 2 next" but the output shold be 4 x "Output ..." on page 1 and on page 2 "Output ..." only shows up once (should be twice).
Do i need another "<xsl:for-each..." around "Output..." in the code below or is it something completely else, that im not getting?
Well it brought us closer and with a little adjustment (removal of "=") so that the last item on current page doesn't show up as first item on next page:
<xsl:if test="position() <= $jump and position() > ($jump - $itemsToDisplay)">
IT WORKS PERFECTLY!... and event better from your code and explaining I get most of what is happening :)
News list pages using xslt
I'm trying to make a newslist in umbraco 4.7.1 using xslt, where the list is limited to a defined number of newsitems...
I have the following pagesetup:
News - News 1
- News 2
- News 3
- etc.
I have managed to make the list, sort it according to date, limit the list to 4 items, but then i'm stuck...
How do I go about adding a "previous / next " function?...
My code:
<xsl:template match="/">
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="umbraco.library:FormatDateTime(nyhedDato, 'dd MMMM, yyyy')" order="descending" />
<xsl:if test="position() <= 4">
<div>
<p><small><xsl:value-of select="umbraco.library:FormatDateTime(nyhedDato, 'dd MMMM, yyyy')"/></small></p>
<H2><xsl:value-of select="newsAreaOverskrift"/></H2>
<p><xsl:value-of select="nyhedBeskrivelse"/></p><br />
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
Hi Crawn,
I havent used v4.7.1 but anyway i think that this should get you working.
First instead you could change your Sorting by date to something like
There is a nice tutorial on paging http://www.nibble.be/?p=11 .
//Fuji
Hi Fuji...
Tried your example:
<xsl:template match="/">
<xsl:variable name="newsitems" select="4"/>
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="current()/nyhedDato" order="descending"/>
<xsl:if test="position() <= newsitems">
...
</xsl:if>
</xsl:for-each>
</xsl:template>
...and nothing came out. I must be doing something wrong
I already looked at the nibble tutorial but couldnt get it to work ( yes i changed all " etc. :) )
Hi there,
You are not getting any output? I noticed in the code you posted you included the "newsitems" variable in your template.
Can you place it outside your template
Can you post your complete code to better understand and help you with your paging?
//fuji
Hi Fuji
And thx again for taking your time to help me...
Complete code:
<?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" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="newsitems" select="4"/>
<xsl:template match="/">
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="current()/nyhedDato" order="descending"/>
<xsl:if test="position() <= newsitems">
Output...
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
//Crawn
Hi Crawn,
Can you try something like this, am not sure how you are accessing your folder containing your newsitems. So am just try get it by using the GetXmlNodeById.
Hope this will solve your problem
//Fuji
Hi Fuji...
I made the Xslt from the std. "List subpages from a changeable source", setup "source" in the macro, and added the macro to the template selecting the parent (id 1107) of my news items.
If i insert all of your code and change the parent node to "1107" i get the following error:
Error occured
System.Xml.Xsl.XslLoadException: The variable or parameter 'itemsToDisplay' is either not defined or it is out of scope.
Hey Crawn Sorry my mistake!!
Change this part to
<xsl:variable name="itemsToDisplay" select="4"/>
and this as well
Hi Fuji...
Getting close now...
With the above code, the paging is working correct, from what i can see... If i have say 6 newsitems and set "newsitems" to "1" paging generates "1 2 3 4 5 6" and "next"... But there is something about the "Output ..."
If newsitems = 4, paging will correctly be " 1 2 next" but the output shold be 4 x "Output ..." on page 1 and on page 2 "Output ..." only shows up once (should be twice).
Do i need another "<xsl:for-each..." around "Output..." in the code below or is it something completely else, that im not getting?
<xsl:for-each select="$sourceXml">
<xsl:sort select="current()/@nyhedDato" order="descending"/>
<xsl:if test="position() = ($jump - $itemsToDisplay)">
Output ...
</xsl:if>
</xsl:for-each>
Hi Fuji...
Getting close now...
With the above code, the paging is working correct, from what i can see... If i have say 6 newsitems and set "newsitems" to "1" paging generates "1 2 3 4 5 6" and "next"... But there is something about the "Output ..."
If newsitems = 4, paging will correctly be " 1 2 next" but the output shold be 4 x "Output ..." on page 1 and on page 2 "Output ..." only shows up once (should be twice).
Do i need another "<xsl:for-each..." around "Output..." in the code below or is it something completely else, that im not getting?
<xsl:for-each select="$sourceXml">
<xsl:sort select="current()/@nyhedDato" order="descending"/>
<xsl:if test="position() = ($jump - $itemsToDisplay)">
Output ...
</xsl:if>
</xsl:for-each>
Can you do try something like
Well it brought us closer and with a little adjustment (removal of "=") so that the last item on current page doesn't show up as first item on next page:
<xsl:if test="position() <= $jump and position() > ($jump - $itemsToDisplay)">
IT WORKS PERFECTLY!... and event better from your code and explaining I get most of what is happening :)
Thumbs up!
Great if you got it working !!
is working on a reply...