Re: [xsl] problems with copying duplicate nodes

Subject: Re: [xsl] problems with copying duplicate nodes
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Wed, 29 Jun 2005 04:16:12 -0700 (PDT)
Hi Rahil,
  You could try something like following..

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:common="http://exslt.org/common";
exclude-result-prefixes="common"
version="1.0">
 
<xsl:output method="html" indent="yes" /> 
 
<xsl:key name="by-td" match="temp/TD" use="." />
 
<xsl:template match="node() | @*"> 
   <xsl:copy>
     <xsl:apply-templates select="node() | @*" />
   </xsl:copy>
</xsl:template>

<xsl:template match="TABLE/TR/TR"> 
   <xsl:variable name="rtf">
     <temp>
       <xsl:copy-of select="TD" />
     </temp>  
   </xsl:variable>
   <xsl:for-each select="$rtf/temp/TD[generate-id() =
generate-id(key('by-td', .)[1])]">
     <xsl:copy-of select="." />
   </xsl:for-each>
</xsl:template>
 
</xsl:stylesheet>

The stylesheet uses node-set function, and Muenchian
Grouping (over a RTF) .. The stylesheet is tested with
Saxon 8.4.

Regards,
Mukul

--- Rahil Qamar <qamar_rahil@xxxxxxxxxxx> wrote:

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


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread