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

Automatically Generating Indexes

Subject: Automatically Generating Indexes
From: "Kirk V. Hastings" <khasting@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Sep 1999 14:38:56 -0700
generating indexes
All,

I've been working on some stylesheets for a local version of TEI lite and have hit a wall with the "index" element, which is used to associate index terms with a specific point in the text:

<p><index level1="Africa" level2="colonial"/>Settler colonies differed from colonies of exploitation by attracting a much larger population of European men and women for permanent settlement....</p>

It was fairly easy to write a module (see below) to generate an index as a unordered list with links to the points in the text using "generate-id". But I'd like to try for something even closer to the print version, with different links to identical terms sequentially listed after that term and level2 terms collected under the correct level1 terms, etc.

Has anyone had any luck with manipulations of this sort?

This:

Abandonment, international policy of: Link1, Link2
Abortion: Link1
Accommodation: Link1, Link2, Link3
Accommodation,
	foreign funding and: Link1
Accommodation,
	right wing and: Link1, Link2
Accommodation,
	violence and: Link1, Link2
Accommodation,
	Yugoslavian situation compared: Link1

Rather than this:

Abandonment, international policy of: Link
Abandonment, international policy of: Link
Abortion: Link
Accommodation: Link
Accommodation: Link
Accommodation: Link
Accommodation,
	foreign funding and: Link
Accommodation,
	right wing and: Link
Accommodation,
	right wing and: Link
Accommodation,
	violence and: Link
Accommodation,
	violence and: Link
Accommodation,
	Yugoslavian situation compared: Link

<!-- index.xsl  Index Generation Module-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="index">
  <a name="{generate-id(.)}"></a>
</xsl:template>

<xsl:template name="book.index">
  <div class="index">
    <h2>Index</h2>
    <a name="index"></a>
    <ul class="nobull">
      <xsl:apply-templates select="//index" mode="index.mode">
	<xsl:sort select="@level1"/>
	<xsl:sort select="@level2"/>
	<xsl:sort select="@level3"/>
	<xsl:sort select="@level4"/>
      </xsl:apply-templates>
    </ul>
  </div>
</xsl:template>

<xsl:template match="index" mode="index.mode">
  <xsl:choose>
    <xsl:when test="@level2 and not(@level3)">
      <li>
	<b><xsl:value-of select="@level1"/>,</b>
	<ul class="nobull">
	  <li>
	    <xsl:value-of select="@level2"/>:
	    <a href="#{generate-id(.)}"> Link</a>
	  </li>
	</ul>
      </li>
    </xsl:when>
    <xsl:when test="@level3 and not(@level4)">
      <li>
	<b><xsl:value-of select="@level1"/>,</b>
	<ul class="nobull">
	  <li>
	    <xsl:value-of select="@level2"/>,
	    <ul class="nobull">
	      <li>
		<xsl:value-of select="@level3"/>:
		<a href="#{generate-id(.)}"> Link</a>
	      </li>
	    </ul>
	  </li>
	</ul>
      </li>
    </xsl:when>
    <xsl:when test="@level4">
      <li>
	<b><xsl:value-of select="@level1"/>,</b>
	<ul class="nobull">
	  <li>
	    <xsl:value-of select="@level2"/>,
	    <ul class="nobull">
	      <li>
		<xsl:value-of select="@level3"/>,
		<ul class="nobull">
		  <xsl:value-of select="@level4"/>:
		  <a href="#{generate-id(.)}"> Link</a>
		</ul>
	      </li>
	    </ul>
	  </li>
	</ul>
      </li>
    </xsl:when>
    <xsl:otherwise>
      <li>
	<b><xsl:value-of select="@level1"/>:</b>
	<a href="#{generate-id(.)}"> Link</a>
      </li>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
Kirk V. Hastings
Digital Publishing Specialist
Library Systems Office
386 Doe Annex
University of California
Berkeley, CA, 94720

khasting@xxxxxxxxxxxxxxxxxxxx


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



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.