This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Building menus


Hi

> I would like to build a menu that sorts the entrys by first character, and
> only display that character once even if several entrys begins with that
> character.
>
> Like this: [A]-[B]-[F]-[I]
>
> I have tryed to match the first character whith proceding-siblings first
> character, but i can't get it to work.

This uses keys for it, but it might be waste of time if you don't have that
many entries. You probably want HTML, hope this will help you with that.

[c:\temp]type menu.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
  <entry name="Flls">
    <fo>lsfjlksdsdfjlsjfsf</fo>
  </entry>
  <entry name="Ajjf"/>
  <entry name="Bjjjdjj"/>
  <entry name="Ilsjdf"/>
  <entry name="Ajjjjj"/>
</root>

[c:\temp]type menu.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" />

<xsl:key name="letter" match="/root/entry" use="substring(@name,1,1)"/>

<xsl:template match="root">
  <xsl:apply-templates select="entry[generate-id(.) =
generate-id(key('letter', substring(@name,1,1)))]">
    <xsl:sort select="@name" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="entry">
  <xsl:text>[</xsl:text>
    <xsl:value-of select="substring(@name,1,1)" />
  <xsl:text>]</xsl:text>
  <xsl:if test="not(position() = last())">
    <xsl:text>-</xsl:text>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

[c:\temp]saxon menu.xml menu.xsl
[A]-[B]-[F]-[I]

--
Jarno Elovirta     jarno.elovirta@codeonline.com
CODEONLINE Ltd.    http://www.codeonline.com
P.O. Box 538 (Ukonvaaja 2 A), FIN-02130 Espoo, Finland
Mobile: +358 40 772 6785 Fax: +358 9 4393 0410

"Hoc non credo; toga mea surrepta est iterum!"


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]