xml - How to generate alphabetical list in xslt -
how create alphatical list link in xslt such as;
<a href="sample.htm?letter=a">a</a> <a href="sample.htm?letter=b">b</a> <a href="sample.htm?letter=c">c</a> ...up to.. <a href="sample.htm?letter=z">z</a>
it can xml transform
<node> <letter>abcdefghijklmnopqrstuvwxyz</text> </node>
or varible?
<xsl:variable name="letter">abcdefghijklmnopqrstuvwxyz</xsl:variable>
xslt 1.0
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html"/> <xsl:variable name="url">sample.htm</xsl:variable> <xsl:variable name="letter">abcdefghijklmnopqrstuvwxyz</xsl:variable> <xsl:template match="/"> <xsl:call-template name="iterate"> <xsl:with-param name="string" select="$letter"/> </xsl:call-template> </xsl:template> <xsl:template name="iterate"> <xsl:param name="string"/> <xsl:param name="length" select="1" /> <xsl:if test="string-length($string)"> <xsl:variable name="char" select="substring($string, 1, 1)" /> <xsl:call-template name="createentry"> <xsl:with-param name="token" select="$char"/> </xsl:call-template> <xsl:call-template name="iterate"> <xsl:with-param name="string" select="substring-after($string, $char)" /> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="createentry"> <xsl:param name="token"/> <a href="{$url}?letter={$token}"><xsl:value-of select="$token"/></a><br/> </xsl:template> </xsl:stylesheet>
explanation
store alphabet variable suggested.
pass whole string function iterate
param string
. [optional parameter: length
]
pass single char function createentry
.
function createentry
output.
if like, give up
Comments
Post a Comment