Re: [xsl] Split with delimiter and remove duplicate with xsl:for-each group

Subject: Re: [xsl] Split with delimiter and remove duplicate with xsl:for-each group
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 30 Jun 2008 15:01:09 +0200
Pankaj Chaturvedi wrote:

<xsl:template name="affiliation">
<xsl:for-each-group select=".//Affiliation" group-by="./Author/Affiliation">
<xsl:value-of select="current-grouping-key()"/>
 <xsl:for-each select="tokenize(., '\[\d+\]')[normalize-space(.)]">
<affil>
  <xsl:value-of select="normalize-space(current-grouping-key())"/>
</affil>
 </xsl:for-each>
</xsl:for-each-group>
</xsl:template>

I would first tokenize, then use xsl:for-each-group to remove duplicates:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="2.0">

<xsl:output method="xml" indent="yes"/>


<xsl:template match="/">
<xsl:variable name="affiliations" as="element()*">
<xsl:for-each select="for $a in Article/AuthorList/Author/Affiliation return tokenize($a, '\[\d+\]')[normalize-space(.)]">
<affil>
<xsl:value-of select="normalize-space(.)"/>
</affil>
</xsl:for-each>
</xsl:variable>
<affiliationList>
<xsl:for-each-group select="$affiliations" group-by=".">
<xsl:copy-of select="current-group()[1]"/>
</xsl:for-each-group>
</affiliationList>
</xsl:template>


</xsl:stylesheet>


--


	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread