Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi!
I want to create a macro for listing all pages in A to Z prefferably with capital letters of each section.
First of all I cant really figure out how to loop ALL nodes and sort them alphabetically.
Someone got an example?
Hi. For example it can be done with something like this:
<xsl:template match="/"> <ul> <xsl:call-template name="a2z"/> </ul> </xsl:template> <xsl:template name="a2z"> <xsl:param name="s" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:if test="string-length($s)"> <li> <xsl:value-of select="substring($s, 1, 1)"/> </li> <xsl:call-template name="a2z"> <xsl:with-param name="s" select="substring($s, 2)"/> </xsl:call-template> </xsl:if> </xsl:template>
To get all the nodes and sort them alphabetically, you can try this:
<xsl:template match="/"> <ul> <xsl:for-each select="umbraco.library:GetXmlAll()//*[@isDoc]"> <xsl:sort select="@nodeName" /> <li><xsl:value-of select="@nodeName" /></li> </xsl:for-each> </ul></xsl:template>
Thx for your help!
The result for those interested is:
<?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"/> <xsl:template match="/"> <ul> <xsl:call-template name="a2z"/> </ul> </xsl:template> <xsl:template name="a2z"> <xsl:param name="s" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:if test="string-length($s)"> <li> <h2><xsl:value-of select="substring($s, 1, 1)"/> </h2> <xsl:variable name="letter" select="substring($s, 1, 1)"/> <ul> <xsl:for-each select="umbraco.library:GetXmlNodeById(1058)//* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:sort select="./@nodeName" order="ascending"/> <xsl:if test="substring(@nodeName, 1,1) = $letter"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:if> </xsl:for-each> </ul> </li> <xsl:call-template name="a2z"> <xsl:with-param name="s" select="substring($s, 2)"/> </xsl:call-template> </xsl:if> </xsl:template></xsl:stylesheet>
Hi froad,
Seems like you're doing a lot of unnecessary looping - here's a couple of suggestions for optimization:
* Instead of calling GetXmlNodeById(1058) in every iteration, grab the node in a variable at the top:
<xsl:variable name="nodeSource" select="umbraco.library:GetXmlNodeById(1058)" />
* Inside the loop you're running through all the nodes everytime, looking for the ones starting with the current letter - you can add that test to the select in the for-each, so that you only grab the nodes you're going to render anyway:
<xsl:for-each select="$nodeSource//*[@isDoc][not(umbracoNaviHide = 1)][starts-with(@nodeName, $letter)]">
Hope you don't mind me pointing this out :-)
/Chriztian
@Chriztian, I felt a little challenge here... what do you think about this XSLT? https://gist.github.com/1391136
wasnt there a to z in auros public sector package?
Yes, the Auros project does have an A to Z package. They used custom .NET controls to handle the listings - still looks very customisable!
@Lee: That's almost exactly like I would've done it myself! i Like them apples :-)
Chriztian: Thx! I just saw it working and didnt look at the optimization. That is much neater :)
The Auros package looks really nice!
let us know what you think of the package, hope it's useful! :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Create A to Z
Hi!
I want to create a macro for listing all pages in A to Z prefferably with capital letters of each section.
First of all I cant really figure out how to loop ALL nodes and sort them alphabetically.
Someone got an example?
Hi. For example it can be done with something like this:
To get all the nodes and sort them alphabetically, you can try this:
Thx for your help!
The result for those interested is:
Hi froad,
Seems like you're doing a lot of unnecessary looping - here's a couple of suggestions for optimization:
* Instead of calling GetXmlNodeById(1058) in every iteration, grab the node in a variable at the top:
* Inside the loop you're running through all the nodes everytime, looking for the ones starting with the current letter - you can add that test to the select in the for-each, so that you only grab the nodes you're going to render anyway:
Hope you don't mind me pointing this out :-)
/Chriztian
@Chriztian, I felt a little challenge here... what do you think about this XSLT? https://gist.github.com/1391136
wasnt there a to z in auros public sector package?
Yes, the Auros project does have an A to Z package. They used custom .NET controls to handle the listings - still looks very customisable!
@Lee: That's almost exactly like I would've done it myself! i Like them apples :-)
/Chriztian
Chriztian: Thx! I just saw it working and didnt look at the optimization. That is much neater :)
The Auros package looks really nice!
let us know what you think of the package, hope it's useful! :)
is working on a reply...