Nibble

Archive for the 'Xslt' Category


Displaying a random image/banner on your umbraco site 9

First some info on the setup:

After installing runway to get a basic site up and running I created a folder in the media section and added several images

randompicturemediajpg

On my homepage document type I added a ‘media picker’ property called ‘Pictures’. There I’ll select the media picture folder.

randompicturecontent

All that’s left now is to write some xslt that will select a random image from the media folder.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!ENTITY nbsp “&#x00A0;”> ]>
<xsl:stylesheet 
    version=”1.0″
    xmlns:msxsl=”urn:schemas-microsoft-com:xslt”  
    xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” 
    xmlns:msxml=”urn:schemas-microsoft-com:xslt”
    xmlns:umbraco.library=”urn:umbraco.library”
    xmlns:myFuncs=”urn:my-scripts” 
    exclude-result-prefixes=”msxml myFuncs umbraco.library”>
 
 
<xsl:output method=”xml” omit-xml-declaration=”yes” indent=”yes”/>
 
<xsl:param name=”currentPage”/>
 
<xsl:variable name=”imageRoot” 
    select=”$currentPage/ancestor-or-self:: node[@level = 1]/data [@alias = ‘Pictures’]”/>
 
<msxsl:script implements-prefix=”myFuncs” language=”JavaScript”> 
<![CDATA[
 
var myArray = new Array();
 
function random(){     
    var index = Math.floor(Math.random() * myArray.length);    
    return myArray [index];
}
 
function addtoArray(item){
    myArray.push(item);
}
 
]]>
 
</msxsl:script> 
 
<xsl:template match=”/”>
 
<!– start writing XSLT –>
 
<xsl:call-template name=”buildArray”>
<xsl:with-param name=”arrayNodes” 
    select=”umbraco.library:GetMedia($imageRoot, ‘true’)/node/data[@alias=’umbracoFile’]”/>
</xsl:call-template>
 
<xsl:value-of select=”myFuncs:random()”/>
 
</xsl:template>
 
<xsl:template name=”buildArray”>
<xsl:param name=”arrayNodes”/>
    <xsl:for-each select=”$arrayNodes”>
        <xsl:value-of select=”myFuncs:addtoArray(string(./text()))”/>
    </xsl:for-each>
</xsl:template>
 
</xsl:stylesheet>

This snippet will output the relative url of a random picture from inside the selected media folder ( like /media/44/dsc00033.jpg ).

RandomPicture xslt: download

New Package - Related Links 33

A feature you often see on sites is a list of related links, sometimes all external, sometimes mixed with internal links.

relatedLinks1

relatedLinks3

By default umbrao doesn’t have a dedicated related links datatype, you could use the richtexteditor to manage an unordered list, or maybe even have the links as child documents. But I found a custom ‘related links’ datatype would be a better way in doing this.

So here it is ….

After installing and adding the new datatype to a documenttype, it will render like this:

relatedlinks4

 

First a listbox with the option to move an item up and down and to delete an item (first select the item and then hit the button).

Next is the link title with an new window checkbox next to it (checked by default)

Underneath that you can view the different url types.

  • External Url
  • Internal Url (node number)
  • Internal Url (content picker)

External url is basicly for every link that isn’t a link to a content node. Just type in the url and hit add.

Internal Url (node number) you can use in case you know the node number of the content page you want to link to. Fill in node number and hit add.

Internal Url (content picker)

Fill 1 one of those 3 and hit the corresponding add button to add the link to the list.

After hitting the save button the links will be saved as xml.

<links>
<link type=”external” title=”google” link=”http://google.com” newwindow=”1″ />
</links>

To display the links on your template you’ll create a new xslt (with macro).

Example of an xslt that will render the related links (alias of the related links property in this example is ‘link’):

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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:relatedLinks.library=”urn:relatedLinks.library”
    exclude-result-prefixes=”msxml umbraco.library relatedLinks.library”>
 
 
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
 
<xsl:param name=”currentPage”/>
 
<xsl:template match=”/”>
<ul>
<xsl:for-each select=”relatedLinks.library:getRelatedLinks($currentPage/data [@alias = ‘link’])/links/link”>
<li>
<xsl:value-of select=”./@newwindow”/>
<a href=”{./@link}”>
<xsl:if test=”./@newwindow = ‘1′”>
<xsl:attribute name=”target”>_blank</xsl:attribute>
</xsl:if>
<xsl:choose>
  <xsl:when test=”./@type = ‘external’”>
    <xsl:attribute name=”href”><xsl:value-of select=”./@link”/></xsl:attribute>
  </xsl:when>
  <xsl:otherwise>
    <xsl:attribute name=”href”><xsl:value-of select=”umbraco.library:NiceUrl(./@link)”/></xsl:attribute>
  </xsl:otherwise>
</xsl:choose>
<xsl:value-of select=”./@title”/>
</a>
</li>
 
 
</xsl:for-each>
</ul>
 
</xsl:template>
 
</xsl:stylesheet>

Xslt as text: download

The package was made for v3, but it should also work on v4 (if the db is sql server).

Related links package: download

Thanks to Dieter De Paepe (my summer intern), who did a great job putting this idea into practise.

Converting Linebreaks 3

When using the textbox multiple datatype in umbraco you might want to convert the linebreaks into html <br> tags. This can be done just by checking a checkbox in the insert umbraco field dialog when inserting a field on your template. Just look for the convert linebreaks checkbox.

image

 

image 

 

In xslt you can also do this by using the umbraco library method umbraco.library.ReplaceLineBreaks(System.String)

So that would like a this:

<xsl:value-of select=”umbraco.library:ReplaceLineBreaks(data [@alias = ‘youralias’])”/>

XSLT previous,next example 10

Say you have a structure like this on your site.

xslt

Multiple content items of the same documenttype, like news items. And you want to display a previous and a next link on those news items.

This can be done with some xslt. Here is an example:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:stylesheet [ &lt;!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”/>
 
<xsl:template match=”/”>
 
<!– The fun starts here –>
 
<xsl:for-each select=”$currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘NewsPage’]/node”>
 
<xsl:if test=”$currentPage/@id = current()/@id”>
 
 <xsl:call-template name=”prevnext”>
    <xsl:with-param name=”count” select=”count($currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘NewsPage’]/node)”/>
    <xsl:with-param name=”itemindex” select=”position()”/>
  </xsl:call-template>
</xsl:if>
 
</xsl:for-each>
 
</xsl:template>
 
<xsl:template name=”prevnext” >
<xsl:param name=”count” />
<xsl:param name=”itemindex” />
 
<xsl:if test=”$itemindex > 1″>
<a href=”{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘NewsPage’]/node[$itemindex-1]/@id)}”>
Previous</a>
</xsl:if>
 
<xsl:if test=”$itemindex &lt; $count”>
<a href=”{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘NewsPage’]/node[$itemindex +1]/@id)}”>
Next </a>
</xsl:if>
 
</xsl:template>
 
</xsl:stylesheet>

The Key is to know how many nodes(newsitems) there are and what the position of the current node is (first, second, .. last) because you don’t need to display a previous link if it’s the first item or a next link if it’s the last.

UPDATE:

Petr Snobelt mailed me the following snippet, which shows another technique (no for-each loop, so should be faster)

<xsl:if test=”count($currentPage/preceding-sibling::node) != 0″>
previous
<a href=”{umbraco.library:NiceUrl($currentPage/preceding-sibling::node[1]/@id)}”>
 <xsl:value-of select=”$currentPage/preceding-sibling::node[1]/@nodeName”/>
</a>
<br />
</xsl:if>
 
<xsl:if test=”count($currentPage/following-sibling::node) != 0″>
next
<a href=”{umbraco.library:NiceUrl($currentPage/following-sibling::node[1]/@id)}”>
 <xsl:value-of select=”$currentPage/following-sibling::node[1]/@nodeName”/>
</a>
</xsl:if>

Creating a youtube macro for umbraco (with xslt extension) 19

I got this request from Bernie.

He wanted a way to insert youtube videos into the richtexteditor by only supplying the link to the video (like http://www.youtube.com/watch?v=fruHQhNe-UM)

When inserting the macro you would get this screen, only asking for the link.

image

After hitting ok it will insert the embed code and the video will be visible on the page.

I’ll go through the different steps I did to develop this macro.

First take a look at the embed code supplied by youtube.

<object width=”425″ height=”344″>
<param name=”movie” value=”http://www.youtube.com/v/fruHQhNe-UM&hl=en&fs=1″></param>
<param name=”allowFullScreen” value=”true”></param>
<embed src=”http://www.youtube.com/v/fruHQhNe-UM&hl=en&fs=1″ 
type=”application/x-shockwave-flash” allowfullscreen=”true” width=”425″ height=”344″>
</embed>
</object>

The src attibute of the embed tag will contain the location of the video. When you compare this to the url

url: http://www.youtube.com/watch?v=fruHQhNe-UM

src: http://www.youtube.com/v/fruHQhNe-UM&hl=en&fs=1

You’ll notice that the important part is the video id. So we will need to get the video id out of the url and insert this into the src attribute of the embed code.

I did this by creating an xslt extension ( you can probably do this without the extension but this was the fastes way for me).

So I made a youtube class

public class YouTube
    {
        public static string getVideoId(string url)
        {
            Regex testYouTube = new Regex(@”(\?v=)(\w[\w|-]*)”);
 
           
            foreach (Match tempMatch in testYouTube.Matches(url))
            {
               
                return(tempMatch.Value.Substring(3, tempMatch.Value.Length - 3));
            }
 
            return “”;
        }
    }

 

And hooked this up in umbraco so I could use it as an xslt extension ( you do this by exposing your class in the \config\xsltExtensions.config file ).

With that in place it’s time to create the xslt file ( with macro )

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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:YouTube=”urn:YouTube”
    xmlns:umbraco.library=”urn:umbraco.library”
    exclude-result-prefixes=”msxml umbraco.library YouTube”>
 
 
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
 
<xsl:param name=”currentPage”/>
<xsl:variable name=”url” select=”//YoutubeUrl”/>
<xsl:template match=”/”>
 
 
<object width=”425″ height=”355″>
<param name=”movie” value=”http://www.youtube.com/v/{YouTube:getVideoId($url)}&amp;hl=en”></param>
<param name=”wmode” value=”transparent”></param>
<embed src=”http://www.youtube.com/v/{YouTube:getVideoId($url)}&amp;hl=en” type=”application/x-shockwave-flash” wmode=”transparent” width=”425″ height=”355″></embed>
</object>
 
</xsl:template>
 
</xsl:stylesheet>

 

This will return the embed code and get the video id from the url (wich is a parameter of the macro ) by calling the xslt extension.

Macro parameters look like this:

image

Adding a language selector to your multilingual umbraco site 14

Create mutlilingual sites with umbraco, there are several approaches in doing this, the one I use the most is to have multiple ‘top level’ nodes (I’ll make a screencast of this in a future post). So for each language you would have a top level node.

The content tree would look like this:

languageselectorcontent

I would like to add a language selector on the site, a dropdown with all languages that will redirect to the selected langauge homepage. How to do this ?

languageselector

I’ll first add a new property to the top level node document type. This will store the text that is displayed in the dropdown.

languageselectordocumenttype

Next step is to create a new xslt file (with macro).

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
 
            
 
<xsl:template match=”/”>
<form>
<select name=”langselection” onchange=”loadPage(this.form.elements[0])” target=”_parent._top” >
<option selected=”selected”>– Please select –</option>
 
  <xsl:for-each select=”$currentPage/ancestor::root/node”>
         
         <option value=”{umbraco.library:NiceUrl(@id)}”><xsl:value-of select=”data [@alias = ‘language’]”/></option>      
    
  </xsl:for-each>
</select>
</form>
 
</xsl:template>
 
</xsl:stylesheet>

This will output the html code for the dropdown. The most important part is the for-each loop, wich will loop all top level nodes, add the url of the top level node as a value of the dropdown option and add the content of the language property as the displayed text of the drop down option.

Now you can add the macro to your template, but you’ll also need to add a little javascript.

<script language=“JavaScript”>
 
function loadPage(list) {
 
  location.href=list.options[list.selectedIndex].value
 
}
 
</script>

XSLT formatting dates 4

Recently I needed to get a date in this format : April 19th 2008

Getting a format like ‘April 19 2008′ is easy, you can just use the umbraco library method FormatDateTime. But to get to the ‘April 19th 2008′ format I needed to write a some extra xslt.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
<xsl:template match=”/”>
 
<!– The fun starts here –>
 
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<xsl:variable name=”day” select=”substring(@createDate,9,2)” />
 
<xsl:choose>
<xsl:when test=”$day = ‘01′ or $day = ‘21′”>
<xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’MMMM d’)”/>st <xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’yyyy’)”/>
 
</xsl:when>
<xsl:when test=”$day = ‘02′ or $day = ‘22′”>
<xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’MMMM d’)”/>nd <xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’yyyy’)”/>
 
</xsl:when>
<xsl:when test=”$day = ‘03′ or $day = ‘23′”>
<xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’MMMM d’)”/>rd <xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’yyyy’)”/>
 
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’MMMM d’)”/>th <xsl:value-of select=”umbraco.library:FormatDateTime(@createDate,’yyyy’)”/>
</xsl:otherwise>
</xsl:choose>
 
</xsl:for-each>
 
 
</xsl:template>
 
</xsl:stylesheet>

First I created a variable day that retrieves the day out of the createdate and then depending on wich day it is I add ’st’, ‘nd’, ‘rd’ or ‘th’.

Umbraco Content Picker Datatype 3

Umbraco has a bunch of default data types. One of them is the content picker. You can find the data types in the developer section of umbraco. When you are unfamiliar with umbraco basics like document types and data types, read this great article on the official umbraco blog http://umbraco.org/blog/2007/12/3/dec-3-umbraco-basics-document-types

So when do you use the content picker datatype, lets say you have a site which has a listing of staff members and on your homepage you want to display a ’staff member of the month’. So on your homepage document types you create a new property ’staff member of the month’ and choose ‘Content Picker’  as Type.

When you go to the content and select your homepage you will have the option to select the ’staff member of the month’. When clicking on choose a new window will open with a treeview of the content and there you only need navigate and select the ’staff member’.

image 

 

After saving the document, the nodeid of the staff member will be saved as ’staff member of the month’. So to display this on our homepage we need to write a little xslt. Because a <?UMBRACO_GETITEM field=”#staffmemberofthemonth”/> will only display the nodeid.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>

 

<xsl:template match=”/”>

<a href=”{umbraco.library:NiceUrl($currentPage/data [@alias = ’staffmemberofthemonth’])}”>

<xsl:value-of select=”umbraco.library:GetXmlNodeById($currentPage/data [@alias = ’staffmemberofthemonth’])/@nodeName”/>

</a>

</xsl:template>

 

</xsl:stylesheet>

So $currentPage/data [@alias = ’staffmemberofthemonth’] will get the nodeid of our staff member and with the umbraco library method GetXmlNodeById we can get the xml of the node and have acces to its properties.

XSLT List x most recent documents 4

Something you see on loads of site homepages is a list of the x most recent newsitems.

In the umbraco backend you would have a structure simular to this example:

xslt

A Homepage with different types of documents underneath and somewhere in that underlying structure you will also have newsitems documents.

So how do we get a list of the 5 most recent newsitems on the homepage.

Take a look at the example below, I started from the “list sub pages from current page template” in umbraco and added a couple of lines.

First I created a variable that will hold the number of items to display. Then I adjusted the select in the for-each loop to only get the child nodes of NewsPage documents.

Next I sort the items on createDate and the final code I added is an if condition to check if the current position in the loop is lower or equal to the variable (itemsToDisplay).

 

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
<xsl:variable name=”itemsToDisplay” select=”5″ />
 
<xsl:template match=”/”>
 
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/descendant::node [@nodeTypeAlias = ‘NewsPage’]/node”>
<xsl:sort select=”@createDate” order=”descending”/>
 
<xsl:if test=”position() &lt;= $itemsToDisplay”>
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
 
</xsl:template>
 
</xsl:stylesheet>

Xslt Paging example 25

Default umbraco has a bunch of xslt templates you can choose from when creating a new xslt file, for me about 80% of the time I start from a template and adjust it to my needs. But one thing that is missing is an example of paging, so for those of you who would like to know how to add paging to a list, check out the examples below. To change the number of items displayed just change the recordsPerPage variable. I started from the “list sub pages from current page template” in umbraco and added 2 examples with paging below (one with only a previous and a next link and another example that also adds page numbers).

 

Without paging ( List Sub Pages From Current Page template )

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
<xsl:template match=”/”>
 
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:for-each>
</ul>
 
</xsl:template>
 
</xsl:stylesheet>

 

With paging ( previous + next )

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
<xsl:template match=”/”>
 
<xsl:variable name=”recordsPerPage” select=”1″/>
 
<xsl:variable name=”pageNumber” >
<xsl:choose>
<!– first page –>
<xsl:when test=”umbraco.library:RequestQueryString(’page’) &lt;= 0 or string(umbraco.library:RequestQueryString(’page’)) = ” or string(umbraco.library:RequestQueryString(’page’)) = ‘NaN’”>0</xsl:when>
<!– what was passed in –>
<xsl:otherwise>
<xsl:value-of select=”umbraco.library:RequestQueryString(’page’)”/>
</xsl:otherwise>
</xsl:choose>
 
</xsl:variable> &nbsp;
 
<xsl:variable name=”numberOfRecords” select=”count($currentPage/node)”/>
 
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<xsl:if test=”position() &gt; $recordsPerPage * number($pageNumber) and
position() &lt;= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
 
<xsl:if test=”$pageNumber &gt; 0″>
<a href=”?page{$pageNumber -1}”>previous </a>
</xsl:if>
 
<xsl:if test=”(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)”>
<a href=”?page={$pageNumber +1}”>next</a>
</xsl:if>
</xsl:template>
 
</xsl:stylesheet>

 

With paging ( previous + page numbers + next )

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!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”/>
 
<xsl:template match=”/”>
 
<xsl:variable name=”recordsPerPage” select=”1″/>
 
<xsl:variable name=”pageNumber” >
<xsl:choose>
<!– first page –>
<xsl:when test=”umbraco.library:RequestQueryString(’page’) &lt;= 0 or string(umbraco.library:RequestQueryString(’page’)) = ” or string(umbraco.library:RequestQueryString(’page’)) = ‘NaN’”>0</xsl:when>
<!– what was passed in –>
<xsl:otherwise>
<xsl:value-of select=”umbraco.library:RequestQueryString(’page’)”/>
</xsl:otherwise>
</xsl:choose>
 
</xsl:variable> &nbsp;
 
<xsl:variable name=”numberOfRecords” select=”count($currentPage/node)”/>
 
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<xsl:if test=”position() &gt; $recordsPerPage * number($pageNumber) and
position() &lt;= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
 
<xsl:if test=”$pageNumber &gt; 0″>
<a href=”?page{$pageNumber -1}”>previous </a>
</xsl:if>
 
<xsl:call-template name=”for.loop”>
<xsl:with-param name=”i”>1</xsl:with-param>
<xsl:with-param name=”page” select=”$pageNumber +1″></xsl:with-param>
<xsl:with-param name=”count” select=”ceiling(count($currentPage/node)div $recordsPerPage)”></xsl:with-param>
</xsl:call-template>
 
<xsl:if test=”(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)”>
<a href=”?page={$pageNumber +1}”>next</a>
</xsl:if>
</xsl:template>
 
<xsl:template name=”for.loop”>
 
<xsl:param name=”i”/>
<xsl:param name=”count”/>
<xsl:param name=”page”/>
<xsl:if test=”$i &lt;= $count”>
 
<xsl:if test=”$page != $i”>
<a href=”{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}” >
 
<xsl:value-of select=”$i” />
</a>
</xsl:if>
 
<xsl:if test=”$page = $i”>
 
<xsl:value-of select=”$i” />
 
</xsl:if>
 
 
</xsl:if>
<xsl:if test=”$i &lt;= $count”>
<xsl:call-template name=”for.loop”>
<xsl:with-param name=”i”>
<xsl:value-of select=”$i + 1″/>
</xsl:with-param>
<xsl:with-param name=”count”>
<xsl:value-of select=”$count”/>
</xsl:with-param>
<xsl:with-param name=”page”>
<xsl:value-of select=”$page”/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>