Subject: Re: [xsl] Using XSLT to build an index From: "Mark" <mark@xxxxxxxxxxxx> Date: Sun, 30 Oct 2011 16:24:37 -0700 |
Thanks, Mark
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>
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using XSLT to build an in, Michael Kay | Thread | Re: [xsl] Using XSLT to build an in, Mark |
Re: [xsl] Using XSLT to build an in, Mark | Date | Re: [xsl] Using XSLT to build an in, Dimitre Novatchev |
Month |