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

problems with copying duplicate nodes

Subject: problems with copying duplicate nodes
From: Rahil Qamar <qamar_rahil@xxxxxxxxxxx>
Date: Wed, 29 Jun 2005 10:09:56 +0100 (BST)
xsl eliminate duplicate nodes
Hi

I read quite a few of the earlier posts on this topic
and tried to work out a solution but it aint working.
Snippets of my code are shown below:

input.xml

<TABLE>
    <TR>
       <TD>Checking existence of Wood</TD>
       <TR>
          <TD>Found values for Wood</TD>
          <TD> The values are x y z</TD>
          <TD>Found values for Wood</TD>
          <TD> The values are x y z</TD>
       </TR>
    </TR>
    <TR>
       <TD>Checking existence of Tree</TD>
       <TR>
          <TD>Found values for Tree</TD>
          <TD> The values are a b c</TD>
       </TR>
    </TR>
</TABLE>

I want to eliminate the duplicate <TD>s inside TABLE
/TR/TR whenever they occur. I tried two solutions but
none of them eliminate the duplicate entries.

input.xsl
--------------------------------------
<xsl:key name="unique" use="TD"
match="/*/TABLE/TR/TR"/> <!--first solution key-->
<!--<xsl:key name="uniqueWithinParent"
match="/*/TABLE/TR/TR/TD"
use="concat(generate-id(parent::TR),.)"/>-->
<!--second solution key-->
   
<xsl:template match="TR">
        <xsl:copy>
             <xsl:for-each select="TR">
                <xsl:copy>
                    <xsl:apply-templates select="."
mode="inner"/>
                </xsl:copy>
            </xsl:for-each>
        </xsl:copy>
</xsl:template>

<xsl:template match="TR" mode="inner">
        <xsl:copy> <!--first solution tried -->
            <xsl:apply-templates
select="TD[count(key('unique', TD)[1]|.)=1]"/>
        </xsl:copy>
        <!--<xsl:copy>--> <!--second solution tried
-->
            <!--<xsl:apply-templates
select="TD[count(.|key('uniqueWithinParent',concat(generate-id(current()),.))[1])=1]"/>-->
           </xsl:copy>-->
</xsl:template>
   
<xsl:template match="TD">
         <xsl:copy-of select="."/>
</xsl:template>
---------------------------
As I mentioned above this code does not eliminate
duplicate entires from being displayed.

The output I want is

output.xml

<TABLE>
    <TR>
       <TD>Checking existence of Wood</TD>
       <TR>
          <TD>Found values for Wood</TD>
          <TD> The values are x y z</TD>
       </TR>
    </TR>
  <TR>
       <TD>Checking existence of Tree</TD>
       <TR>
          <TD>Found values for Tree</TD>
          <TD> The values are a b c</TD>
       </TR>
    </TR>
</TABLE>

There is obviously something wrong with my code but I
cant spot it despite a lot of effort. Could someone
please help.

Thanks a lot
Rahil


		
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com

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.