xsl-list
[Top] [All Lists]

[xsl] Grouping based on key result

2009-03-03 05:48:00
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>