Thomas J.S.: Zugriff auf vorheriges Element bei Sortierung

Beitrag lesen

Hallo,

Problem sind jetzt noch die Anker.
Ich denke nach ... :-)

ich habe jetzt eine Lösung (wenn es dir so reicht?)

Grüße
Thomas
--------- xml ---------------------
<data>
 <allelem>
  <elem name="bbcd">bbcd</elem>
  <elem name="abcd">abcd</elem>
  <elem name="aaa">aaa</elem>
  <elem name="deef">deef</elem>
  <elem name="dada">dada</elem>
  <elem name="bacb">bacb</elem>
  <elem name="efgh">efgh</elem>
  <elem name="waw">waw</elem>
  <elem name="h">h</elem>
  <elem name="waz">waz</elem>
  <elem name="adef">adef</elem>
  <elem name="cece">cece</elem>
  <elem name="cdbb">cdbb</elem>
  <elem name="ghij">ghij</elem>
  <elem name="gghh">gghh</elem>
  <elem name="eeff">eeff</elem>
  <elem name="aaab">aaab</elem>
 </allelem>
</data>
---------------- xsl ------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="firstletter" match="elem" use="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

<xsl:template match="/data">
<html>
<head>
 <title>Untitled</title>
</head>

<body>
 <xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="allelem">
    <xsl:call-template name="abclist" />
 <xsl:apply-templates select="elem" mode="byname">
  <xsl:sort select="@name"/>
 </xsl:apply-templates>
</xsl:template>

<xsl:template name="abclist">
 <xsl:for-each select="elem[generate-id() = generate-id(key('firstletter', translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))[1])]">
  <xsl:sort select="@name"/>
     <a href="#label{substring(@name, 1, 1)}"><xsl:value-of select="substring(@name,1,1)"/></a>&#160;
 </xsl:for-each>
</xsl:template>

<xsl:template match="elem" mode="byname">
 <xsl:if test="generate-id(.) = generate-id(key('firstletter', translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))[1])">
  <xsl:call-template name="groupelembyname">
   <xsl:with-param name="gruppe" select="key('firstletter', translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))" />
  </xsl:call-template>
 </xsl:if>
</xsl:template>

<xsl:template name="groupelembyname">
 <xsl:param name="gruppe" />
   <h1><a id="label{substring($gruppe[1], 1, 1)}">label <xsl:value-of select="substring($gruppe[1], 1, 1)" /></a></h1>
  <xsl:for-each select="$gruppe">
   <xsl:sort select="@name" />
   <p>
    <xsl:value-of select="." />
   </p>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>