[xsl] Grouping based on key result

Subject: [xsl] Grouping based on key result
From: Ganesh Babu N <nbabuganesh@xxxxxxxxx>
Date: Tue, 3 Mar 2009 16:17:31 +0530
Hai All,

Here is my XML:

<author-group>
			<author>
				<given-name>JungKun</given-name>
				<surname>Park</surname>
				<cross-ref refid="aff1">
					<sup>a</sup>
				</cross-ref>
				<cross-ref refid="cor1">
					<sup>&#x204E;</sup>
				</cross-ref>
			</author>
			<author>
				<given-name>HoEun</given-name>
				<surname>Chung</surname>
				<cross-ref refid="aff1">
					<sup>a</sup>
				</cross-ref>
			</author>
			<author>
				<initials>W.S.</initials>
				<given-name>Weon Sang</given-name>
				<surname>Yoo</surname>
				<cross-ref refid="aff2">
					<sup>b</sup>
				</cross-ref>
			</author>
			<affiliation id="aff1">
				<label>a</label>
				<textfn>Department of Consumer Sciences and Retailing, Matthews
Hall, 812 W State Street, Purdue University, West Lafayette, IN
47907-2060, USA</textfn>
			</affiliation>
			<affiliation id="aff2">
				<label>b</label>
				<textfn>Department of Consumer Sciences and Retailing, Matthews
Hall, 812 W State Street, CA,  47907-2060, USA</textfn>
			</affiliation>
		</author-group>

The required output is :
<author>JungKun Park</author>, <author>HoEun Chung</author> and
<author>Weon Sang Yoo</author> (USA)

Means we need to group all the authors belongs to the same country and
also keeping them in the order of their appearance. We cannot group
based on the @id of affiliation, as it will display country for each
author.

Here is my XSL:

<xsl:key name="country" match="affiliation/textfn"
use="parent::affiliation/@id"/>
<xsl:template match="author-group">
     <xsl:variable name="aff" select="key('country' author/cross-ref/@refid)"/>
     <xsl:variable name="tokenizedSample" select="tokenize($aff,', ')"/>
     <xsl:variable name="count" select="$tokenizedSample[last()]"/>

     <xsl:for-each-group select="author" group-adjacent="$count">
        <xsl:apply-templates select="current-group()"/>
       (<xsl:value-of select="current-grouping-key()"/>)
     </xsl:for-each-group>

</xsl:template>

Which is showing error at tokenize () function as  "XPTY0004: A
sequence of more than one item is not allowed as the first argument of
  tokenize()". I can not use [1] after author as i need to process all
the countries of each author

Please help is solving this problem.

Regards,
Ganesh

Current Thread