[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: alphabetic counters

Subject: RE: alphabetic counters
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 10 May 2004 17:17:20 +0100
date counters
> Which is processed by this XSLT fragment:
> 
> <xsl:for-each select="reference">
>    <xsl:text disable-output-escaping="yes"><![CDATA[<a 
> href="#]]></xsl:text><xsl:value-of select="@cite"/><xsl:text 
> disable-output-escaping="yes"><![CDATA[">]]></xsl:text>
>    <xsl:value-of select="id(@cite)/@author" />
>    <xsl:if test="id(@cite)/@year != ''"><xsl:text> 
> </xsl:text><xsl:value-of select="id(@cite)/@year" /></xsl:if>
>    <xsl:text disable-output-escaping="yes"><![CDATA[</a>]]></xsl:text>
>    <xsl:if test="position() != last()"><xsl:text>, 
> </xsl:text></xsl:if>
> </xsl:for-each>

First thing is to tidy up this garbage. This code is trying to produce
serialized HTML as output, bypassing the creating of a result tree. This is
like escaping into assembly language when writing Java - it's unmaintainable
and totally unecessary. You want:

<xsl:for-each select="reference">
   <a href="#{@cite}"/>
    <xsl:value-of select="id(@cite)/@author" />
    <xsl:if test="id(@cite)/@year != ''">
       <xsl:value-of select="id(@cite)/@year" />
    </xsl:if>
   </a>
   <xsl:if test="position() != last()">,&#xa;</xsl:if> 
</xsl:for-each>

> 
> What my problem is, is that references like the above are supposed to 
> be suffixed by a lower case alphabetic character ('a', 'b', 
> etc.) after 
> the year if there are multiple 'citation' elements with identical 
> values for 'author' and 'year'. I have no idea how to go about doing 
> this. Can anyone suggest how to do this?

First define a key:

<xsl:key name="k" match="citation" use="concat(@author, '/', @year)"/>

To find all the citations for a given author and year:

<xsl:variable name="group" select="key('k', concat($author, '/', $year))"/>

To find the position of a given citation $id in this list:

<xsl:variable name="p">
  <xsl:for-each select="key('k', concat($author, '/', $year))">
    <xsl:if test="@id = $id"><xsl:value-of select="position()"/></xsl:if>
  </xsl:for-each>
</xsl:variable>

To add your suffix:

<xsl:variable name="suffix"
    select="substring('abcdefghijklm', $p - 1, 1)"/>

In XSLT 2.0 you can do:

<xsl:variable name="suffix"
  select="substring('abcdefghijklm', 
                    count(key('k', @author, '/', @year))[.<<current()] - 1,
1)"/>
                
Not tested (and requires finishing)

Michael Kay

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.