Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 610 posts 906 karma points
    Nov 23, 2011 @ 16:03
    Fredrik Esseen
    0

    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?

  • Rodion Novoselov 694 posts 859 karma points
    Nov 23, 2011 @ 18:36
    Rodion Novoselov
    0

    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>
  • jc 64 posts 101 karma points
    Nov 23, 2011 @ 20:46
    jc
    0

    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>
  • Fredrik Esseen 610 posts 906 karma points
    Nov 24, 2011 @ 09:51
    Fredrik Esseen
    0

    Thx for your help!

    The result for those interested is:

    <?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"/>
        
        <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>
                &nbsp;
              </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>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 24, 2011 @ 10:06
    Chriztian Steinmeier
    0

    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 

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 24, 2011 @ 12:23
    Lee Kelleher
    0

    @Chriztian, I felt a little challenge here... what do you think about this XSLT? https://gist.github.com/1391136

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 24, 2011 @ 12:53
    Ismail Mayat
    1

    wasnt there a to z in auros public sector package?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 24, 2011 @ 12:59
    Lee Kelleher
    0

    Yes, the Auros project does have an A to Z package. They used custom .NET controls to handle the listings - still looks very customisable!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 24, 2011 @ 13:03
    Chriztian Steinmeier
    0

    @Lee: That's almost exactly like I would've done it myself! i Like them apples :-)

    /Chriztian

  • Fredrik Esseen 610 posts 906 karma points
    Nov 24, 2011 @ 13:31
    Fredrik Esseen
    0

    Chriztian: Thx! I just saw it working and didnt look at the optimization. That is much neater :)

    The Auros package looks really nice!

  • Auros 1 post 156 karma points
    Dec 08, 2011 @ 13:06
    Auros
    0

    let us know what you think of the package, hope it's useful! :)

Please Sign in or register to post replies

Write your reply to:

Draft