Re: sorting a list of titles after removal of stopword
>I am trying to sort a list of titles that have been processed using XSLT to >remove all leading articles (stopwords "A", "An", and "The"), and to remove >special characters such as [, ], ^, and so on. > ><B>Sorted: </B><P /> ><xsl:apply-templates select="//ead/book/title" mode="with-stoplist"> ><xsl:sort select="$stoplist" order="descending"/> ></xsl:apply-templates> > One problem is that you are using an expresion in "xsl:sort select" which does not depend on the context node: its just a global variable. You are saying all the records have the same key, so they will just come out in document order. What you need is an expression that, given the context of a title element, will return a string containing the edited title (stop words removed). This cannot be done with standard XSLT, but you have three possibilities: 1) You are using Saxon, which has an extension saxon:function which lets you write a function in XSLT - more or less the contents of your mode="with-stoplist" template. 2) Do the transform in two phases: first add an attribute to each title containing the edited form, then do a sort on this attribute. If you use the node-set extension you can do this in one transformation, otherwise you need two. 3) If you want 100% XSLT 1.0 then use Dimitri's generic sort library: find this through the list archive. This doesn't sort using xsl:sort, so avoids the problem of cramming the stop list deletion function into an XPath expression. Regards, Trevor Nash -- Traditional training & distance learning, Consultancy by email Melvaig Software Engineering Limited voice: +44 (0) 1445 771 271 email: tcn@xxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
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