[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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: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.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. 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".
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|