Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] XSLT/XPath Question (Grouping Authors by First Character of Last Name)

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 3/4/2007 9:01:00 PM
At 2007-03-04 12:41 -0800, Kevin Grover wrote:
Excellent!  That's exactly what I was trying to achieve.  Thanks.



It also seems that this may have answered my other question: about
saving the list of letters so I can iterate over them later (to make
links to the TOC entries.  It looks like I can just take the main
for-each loop and save that code to a variable.  I'll play with it.

I guess I need to play with the <xsl:key/>'s some more.  The code does
not seem obvious to me at all....

Sorry 'bout that ... little time to document when doing volunteer work.



There is a discussion of the XSL key facility in section 3.4 of the 
free developer resources section of our web site.



Thankfully, the concepts are easy once you hear how they work.



On 3/3/07, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
t:\>type grover.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

   <xsl:output method="text"/>

Declare a lookup table with all authors in the left column and the 
first letter of their file-as string in the right column:



   <xsl:key name="alet" match="author"
            use="substring(name/@file-as,1,1)"/>

   <xsl:template match="/">

Looking at all authors, keep only those in the current node list that 
are the first in document order ... checking the order by checking 
the unique identifier for the current node against the unique 
identifier for the first one found using the key() lookup feature:



    <xsl:for-each select="*/author[generate-id(.)=



generate-id(key('alet',substring(name/@file-as,1,1))[1])]">
      <xsl:text>&#xA;&#xA;</xsl:text>
      <xsl:value-of select="substring(name/@file-as,1,1)"/>
      <xsl:text>&#xA;</xsl:text>

Look up all authors that have the same first letter as the author 
being processed:



      <xsl:for-each select="key('alet',substring(name/@file-as,1,1))">
        <xsl:value-of select="name/@file-as"/>
        <xsl:text>&#xA;</xsl:text>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

I hope this helps ... good luck in your work with XSL.



. . . . . . . . . . . Ken



--
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent