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

Re: Using XSLT to build an index

Subject: Re: Using XSLT to build an index
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sun, 30 Oct 2011 23:07:34 +0000
Re:  Using XSLT to build an index
On 30/10/2011 22:07, G. Ken Holman wrote:
At 2011-10-30 14:47 -0700, Mark wrote:
The list archives did not seem to contain an XSLT stylesheet that could index an XML file, but I may have missed it. Is it practical to write my own XSLT 2 indexing stylesheet? If so, I have a bilingual XML file that I want to index.

Where you simply want all words, except your stop words, collected to automate the index generation, I've never been successful with automated indexing myself. For my books I've authored the components of the index, and then pointed to those components from within the code.
Certainly, an automatically-generated index will never come close to one produced by hand. However, the index to the Saxon documentation at http://www.saxonica.com/documentation/index-entries/intro.xml is automatically-generated, and we thought it better than having nothing at all.

This index is constructed by taking all the title, subtitle, and index elements (the index tag allows phrases to be marked for manual indexing), and extracts tokens using

<xsl:for-each select="tokenize(replace(.,'\.(\s|$)','$1'),'[\W\p{S}-[\-\.'']]+')[not(.=$stop-words)]">
<token section="{$section}" page="{$page}" subpage="{$subpage}" title="{$title}" value="{.}"/>
</xsl:for-each>


It then sorts and groups the tokens to produce the index.

I wouldn't claim this regular expression is perfect, but it worked for the intended purpose. It could easily be improved if we had time to work on it.

The replace() preprocesses the input by removing any full stop that is followed by a space or by the end of the string.

The tokenize() then splits the string on any separator that is a non-word character or a Unicode separator character, other than hyphen or full-stop. This means that for the Saxon index, hyphens and embedded periods are considered word characters, resulting in index entries for terms like "xsl:strip-space" and "1.1".

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.