Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created November 24, 2011 11:22
Show Gist options
  • Save leekelleher/1391136 to your computer and use it in GitHub Desktop.
Save leekelleher/1391136 to your computer and use it in GitHub Desktop.
XSLT snippet for generating an A to Z list for Umbraco content nodes.
<?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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:key name="document-starts-with" match="*[@isDoc]" use="translate(substring(@nodeName, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:param name="currentPage" />
<xsl:template match="/">
<xsl:variable name="letters" select="umbraco.library:Split('A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z', ',')" />
<xsl:apply-templates select="$letters" mode="index" />
<xsl:apply-templates select="$letters" mode="list" />
</xsl:template>
<xsl:template match="values" mode="index">
<ul>
<xsl:apply-templates select="value" mode="index" />
</ul>
</xsl:template>
<xsl:template match="value" mode="index">
<li>
<a href="#{text()}">
<xsl:value-of select="text()"/>
</a>
</li>
</xsl:template>
<xsl:template match="values" mode="list">
<div class="wrapper">
<xsl:apply-templates select="value" mode="list" />
</div>
</xsl:template>
<xsl:template match="value" mode="list">
<xsl:variable name="letter" select="text()" />
<xsl:for-each select="$currentPage/@*[1]">
<xsl:if test="key('document-starts-with', $letter)">
<div id="{$letter}">
<h3>
<xsl:value-of select="$letter"/>
</h3>
<ul>
<xsl:apply-templates select="key('document-starts-with', $letter)" mode="list" />
</ul>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="*[@isDoc]" mode="list">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
@leekelleher
Copy link
Author

Curious if there is a way to get around the $currentPage/@*[1] hack - to return the context back to the Umbraco nodes. Still beautiful markup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment