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

Re: Template removes non-duplicate elements

Subject: Re: Template removes non-duplicate elements
From: "Mark Wilson" <mark@xxxxxxxxxxxx>
Date: Sat, 14 Mar 2009 07:11:54 -0700
Re:  Template removes non-duplicate elements
Thank you Michael ( and Mr Bigui and Mr Maden),
The Xref items are the only duplicates in the file, I just enclosed the other records because my very bad code was removing some of them by mistake. I cut and pasted the example and was careless: the two Porta Coeli entries were an accidental duplicate.


I am working with the 4th ed. of your book, but find at the age of 70, learning XPath a difficult task. While I can read your solution quite easily, I could never have composed it.

The xsl-list membership has been very helpful,
Thanks for taking the time.
Mark

--------------------------------------------------
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Sent: Saturday, March 14, 2009 3:23 AM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Template removes non-duplicate elements

You need to explain the rules. If you consider the two "Porta Coeli" entries
to be distinct, you need to say why.


Perhaps you only want to eliminate duplicates if they have an Xref/Heading
element? In that case, change

<xsl:copy-of select="current-group()[1]"/>

to

<xsl:copy-of select="current-group()[if (Xref/Heading) then 1 else
true()]"/>

(I think that's the first time I have ever encountered a genuine use case
for a predicate that can be either numeric or boolean...)

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Mark Wilson [mailto:mark@xxxxxxxxxxxx]
Sent: 14 March 2009 01:42
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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>

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-2013 All Rights Reserved.