Subject: Re: [xsl] XSLT/XPath Question (Grouping Authors by First Character of Last Name)|
From: "Kevin Grover" <kevin@xxxxxxxxxxxxxxx>
Date: Sun, 4 Mar 2007 12:23:28 -0800
> I tried embedding something like the above "for $a in.." into > an XSLT 2.0 stylesheet, and assign it to a variable, but I > get an error from saxon when I tried it.
There's really not much point in telling us this. If you tell us exactly what you coded and what error message you got, then we can help you understand what you did wrong. If you only tell us roughly what you coded and that Saxon didn't like it, then all we can do is to extend our symphathy.
Sorry, I was not meaning to imply anything bad about saxon, I meant it to demonstrate that I'd tried many various approaches, and came up short.
I'm a nutshell, I was trying to use the FLWOR expression to build a list of the characters that I could later iterate over. I dug through my old files and discovered that I did not save the failing expressions. I don't think it was any fault of saxon, just of my own ignorance.
<xsl:variable name="letters" select="for $a in //author return substring($a,1,1)"/>
but I had distinct or unique keywords in there. When I tried the above yesterday, or worked, but I could not iterator over it in a for each loop.
As Dimitre points out, you've got a simple grouping problem here and xsl:for-each-group should sort it out very easily.
I didn't say this in the original post, but I was hoping to get this working using XSLT 1.0 (just because I'm annoyed that it's been so hard). Dimitre's XSLT 2.0 code is much cleaner, and I'll probably move my XSL stuff to 2.0 and start using saxon (I was using xsltproc from libxslt)
Thanks for the quick feedback. Sorry this reply took so long, I looked through my SVN repository to see if I saved some of the old test files.