[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping based on key result

Subject: Re: Grouping based on key result
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 3 Mar 2009 11:40:28 GMT
Re:  Grouping based on key result
> 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()"

you could avoid that by applying tokenize to each item separately ie not
tokenize($aff,', ')
but
$aff/tokenize(.,', ')
(by the way it's safer to use ',\s+' rather than ', ' unless you know
your input is highly regular.)

However this can not work as you intend. 
     <xsl:for-each-group select="author" group-adjacent="$count">
variables hold values not expression fragments so $count (or any other
variable)  would have the same value each time it is evaluated, so all
items will appear in the same group.

the group-aadjacent attribute needs to hold an expression that evaluates
to different values at group boundaries It could be inlined into teh
attribute, but here I suggest a function:






<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:for-each-group select="author" group-adjacent="f:country(.)">
        <xsl:apply-templates select="current-group()"/>
       (<xsl:value-of select="current-grouping-key()"/>)
     </xsl:for-each-group>

</xsl:template>

<xsl:template match="author">
<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:sequence select="key('country', $a/cross-ref/@refid,root($a))/tokenize(.,',\s+')[last()]"/>
</xsl:function>

</xsl:stylesheet>


$ saxon9 ag.xml ag.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<author>JungKun Park</author>
<author>HoEun Chung</author>
<author>Weon Sang Yoo</author>
       (USA)




________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.