[XML-SIG] XSLT sorting by "authors" element, with multiple
uche.ogbuji at fourthought.com
Sat Jun 7 01:22:32 EDT 2003
> "Jon Berry" <jberry at sandia.gov> writes:
> | I'd like to sort by the last name, alphabetically by
> | first differing author. So the algorithm would be:
> | * within each article, sort authors by lastname
> | * to compare Article A with Article B:
> | * Look at last names of first author (if different,
> | comparison done)
> | * else if first authors are the same, look at second authors,
> | * etc.
> | * if not distinguished, go on to next sorting key (say
> | 'title')
> | Noting of course that we might be comparing articles with
> | different numbers of authors.
> | In initial searches, it looked like the xsl:for-each-group
> | and/or xsl:function constructs might help, but they don't seem
> | to be supported by the current PyXML/4Suite implementations.
> | So, with the constraint that I'm trying to avoid buying a book for now,
> | is this doable using templates, easy, and currently implementable
> | with free software?
> I believe that using extension functions is a good approach to
> cope with your problem.
> The primary cause of your problem is that the xsl:sort looks at
> only the value of the first node, instead of all the selected
> nodes. For example, the following xsl:sort element selects all
> the last names of an article's authors, but only the first last
> name is used as a sort key.
> <xsl:sort select="authors/person/@lastname" order="ascending" />
> So, a simple solution is to change this behavior of xsl:sort by
> defining an extension function like this:
> <xsl:sort select="ext:strings(authors/person/@lastname)" order="ascending" />
> where the extension function ext:strings() can be defined, for
> example, as follows:
> def strings(context, nodeset):
> return "".join(map(lambda x: x.nodeValue, nodeset))
> It seems very Pythonic, doesn't it? :-) See documentation for
> more information on extension functions in Python.
Just being helpful:
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Using libxml in Python - http://www.xml.com/pub/a/2003/05/14/py-xml.html
Charming Jython - http://www-106.ibm.com/developerworks/java/library/j-jython.h
The commons of creativity - http://www-106.ibm.com/developerworks/xml/library/x
Is XQuery an omni-tool? - http://www.adtmag.com/article.asp?id=7620
More information about the XML-SIG