xsl-list
[Top] [All Lists]

problems with copying duplicate nodes

2005-06-29 02:09:56
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

--~------------------------------------------------------------------
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>
--~--