|
Subject: Re: [xsl] Grouping based on key result From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 06 Mar 2009 07:47:05 -0500 |
Can somebody respond to my problem. Please.
T:\ftemp>type ganesh.xml <author-group> <author> <given-name>T.</given-name> <surname>Miwa</surname> <cross-ref refid="aff2"><sup>b</sup></cross-ref> </author> <author> <given-name>T.</given-name> <surname>Nomura</surname> <cross-ref refid="aff2"><sup>b</sup></cross-ref> </author> <author> <given-name>J.</given-name> <surname>Sakakibara</surname> <cross-ref refid="aff1"><sup>a</sup></cross-ref> </author> <author> <given-name>H.</given-name> <surname>Shintani</surname> <cross-ref refid="aff1"><sup>a</sup></cross-ref> </author> <author> <initials>B.E.</initials> <given-name>B.E.</given-name> <surname>Ungerechts</surname> <cross-ref refid="aff3"><sup>c</sup></cross-ref> </author>
<affiliation id="aff1"><label>a</label><textfn>Graduate School of Systems and Information Engineering, University of Tsukuba, Tsukuba 305-8573, Japan</textfn></affiliation>
<affiliation id="aff2"><label>b</label><textfn>Graduate School of Comprehensive Human Sciences, University of Tsukuba, Tsukuba 305-8573, Japan</textfn></affiliation>
<affiliation id="aff3"><label>c</label><textfn>Institute of Sport Sciences, University of Bielefeld, D-33615 Bielefeld, Germany</textfn></affiliation> </author-group>
T:\ftemp>type ganesh.xsl <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="data:,f" exclude-result-prefixes="xs f">
<xsl:output indent="yes" encoding="US-ASCII"/> <xsl:strip-space elements="*"/>
<xsl:key name="country" match="affiliation/textfn"
use="parent::affiliation/@id"/>
<xsl:template match="author-group">
<xsl:variable name="multiple-authors" select="count(author)>1"/>
<xsl:for-each-group select="author" group-adjacent="f:country(.)">
<xsl:apply-templates select="current-group()">
<xsl:with-param name="multiple-authors" select="$multiple-authors"/>
<xsl:with-param name="last-group" select="position()=last()"/>
</xsl:apply-templates>
(<xsl:value-of select="current-grouping-key()"/>)
</xsl:for-each-group><xsl:template match="author">
<xsl:param name="multiple-authors" as="xs:boolean"/>
<xsl:param name="last-group" as="xs:boolean"/>
<xsl:choose>
<xsl:when test="position() = last() and $last-group and $multiple-authors">
<xsl:text> and </xsl:text>
</xsl:when>
<xsl:when test="position() != 1">
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
<author><xsl:value-of select="given-name,surname"/></author>
</xsl:template><xsl:function name="f:country" as="xs:string">
<xsl:param name="a" as="element()"/>
<xsl:choose>
<xsl:when test="$a/cross-ref">
<xsl:sequence select="key('country',
$a/cross-ref/@refid,root($a))/tokenize(.,',\s+')[last()]"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence
select="$a/following-sibling::affiliation[1]/tokenize(.,',\s+')[last()]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function></xsl:stylesheet> T:\ftemp>rem Done!
-- XQuery/XSLT training in Prague, CZ 2009-03 http://www.xmlprague.cz Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Grouping based on key res, Ganesh Babu N | Thread | Re: [xsl] Grouping based on key res, G. Ken Holman |
| RE: [xsl] passing parameters to XSL, Michael Kay | Date | Re: [xsl] Grouping based on key res, G. Ken Holman |
| Month |