Hello,
Try this:
<xsl:template match="/List">
<List>
<xsl:for-each-group select="Item" group-by=".">
<xsl:copy-of select="current-group()[1]"/>
</xsl:for-each-group>
</List>
</xsl:template>
The identity template is never run and therefore not
usefull; Listing 3 tries to group by elements that don't
always exist.
Regards,
EB
-----Original Message-----
From: Mark Wilson [mailto:mark(_at_)knihtisk(_dot_)org]
Sent: Saturday, March 14, 2009 2:42 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Template removes non-duplicate elements
My attempt at duplicate removal is failing in that it removes more than I
want it to. Listing 2 is the input file. The output file should
have one of
the two duplicate initial <item>s removed (Listing 1), everything else
should stay. My broken template is in Listing 3. It removes one of the
duplicates and two of the three non-duplicate <Item> s. (see Listing 4).
Can someone help me fix my template?
Thanks,
Mark
Listing 1.
<Item>
<Heading entry="subject">Monasteries</Heading>
<Xref xref="see">
<Heading entry="subject">Abbeys and Monasteries</Heading>
</Xref>
</Item>
Listing 2.
<List>
<Item>
<Heading entry="subject">Monasteries</Heading>
<Xref xref="see">
<Heading entry="subject">Abbeys and Monasteries</Heading>
</Xref>
</Item>
<Item>
<Heading entry="subject">Monasteries</Heading>
<Xref xref="see">
<Heading entry="subject">Abbeys and Monasteries</Heading>
</Xref>
</Item>
<Item>
<Heading entry="subject">Abbeys and Monasteries</Heading>
<Level1>
<SubDiv1>St Nicholas. Postal Card</SubDiv1>
</Level1>
</Item>
<Item>
<Heading entry="subject">Abbeys and Monasteries</Heading>
<Level1>
<SubDiv1>Porta Coeli</SubDiv1>
</Level1>
</Item>
<Item>
<Heading entry="subject">Abbeys and Monasteries</Heading>
<Level1>
<SubDiv1>Porta Coeli</SubDiv1>
</Level1>
</Item>
<Item>
<Heading entry="subject">Abbeys and Monasteries</Heading>
<Level1>
<SubDiv1>Strahov</SubDiv1>
<Level2>
<SubDiv2>Strahov Madonna</SubDiv2>
</Level2>
</Level1>
</Item>
</List>
Listing 3.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
version="2.0">
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<List>
<xsl:for-each-group select="//Item" group-by="concat(Heading,
Xref/Heading)">
<xsl:copy-of select="current-group()[1]"
copy-namespaces="no"/>
</xsl:for-each-group>
</List>
</xsl:template>
</xsl:stylesheet>
Listing 4.
<List>
<Item>
<Heading entry="subject">Abbeys and Monasteries</Heading>
<Level1>
<SubDiv1>St Nicholas. Postal Card</SubDiv1>
</Level1>
</Item>
<Item>
<Heading entry="subject">Monasteries</Heading>
<Xref xref="see">
<Heading entry="subject">Abbeys and Monasteries</Heading>
</Xref>
</Item>
</List>
--~------------------------------------------------------------------
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>
--~--