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

Trouble removing dup elements based on attributes

Subject: Trouble removing dup elements based on attributes
From: "Al Bean" <albean88@xxxxxxxxxxx>
Date: Fri, 24 Jun 2005 23:14:04 +0000
attrib s sam
Hi,

I just started using XSLT today and I'm trying to figure out how to get rid of some duplicated elements. I know that I need to do something to the "XXX" template but I am not sure what to do.

I've tried this for the XXX template but it does not work:
<xsl:template mode="XXX" match="attrib[@name='Names']/rs/row">
<xsl:if test="not(@firstname = preceding::attrib[@name='Names']/rs/row/@firstname)">
<xsl:element name="ns:name">
<xsl:value-of select="@firstname"/>
</xsl:element>
</xsl:if>
</xsl:template>



Thanks in advance for any help.





---------------------- My XSL ----------------------

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns="http://w.ns.c/ns/prod/">
<xsl:template match="/">
<ns:Products>
<xsl:apply-templates/>
</ns:Products>
</xsl:template>


<xsl:template match="product">
<xsl:element name="ns:Product">
<xsl:element name="ns:Names">
<xsl:apply-templates mode="XXX" select="attrib[@name='Names']/rs/row"/>
</xsl:element>
</xsl:element>
</xsl:template>


   <xsl:template mode="XXX" match="attrib[@name='Names']/rs/row">
       <xsl:element name="ns:name">
           <xsl:value-of select="@firstname"/>
       </xsl:element>
   </xsl:template>
</xsl:transform>


---------------------------------------------------- Input XML : ----------------------------------------------------

<prods>
   <product>
       <attrib name="P">product 1</attrib>
       <attrib name="Names">
           <rs>
               <row firstname="Bill"/>
               <row firstname="Bill"/>
           </rs>
       </attrib>
   </product>
   <product>
       <attrib name="P">product 2</attrib>
       <attrib name="Names">
           <rs>
               <row firstname="Sam"/>
               <row firstname="Ron"/>
               <row firstname="Sam"/>
               <row firstname="Ron"/>
           </rs>
       </attrib>
   </product>
   <product>
       <attrib name="P">product 3</attrib>
       <attrib name="Names">
           <rs>
               <row firstname="Ron"/>
               <row firstname="Sam"/>
               <row firstname="Joe"/>
               <row firstname="Sam"/>

           </rs>
       </attrib>
   </product>
</prods>

----------------------------------------------------
This is the OUTPUT that I want (note no name dups):
----------------------------------------------------

<ns:Products xmlns:ns="http://w.ns.c/ns/prod/">
   <ns:Product>
       <ns:Names>
           <ns:name>Bill</ns:name>
       </ns:Names>
   </ns:Product>
   <ns:Product>
       <ns:Names>
           <ns:name>Sam</ns:name>
           <ns:name>Ron</ns:name>
       </ns:Names>
   </ns:Product>
   <ns:Product>
       <ns:Names>
           <ns:name>Ron</ns:name>
           <ns:name>Joe</ns:name>
           <ns:name>Sam</ns:name>
       </ns:Names>
   </ns:Product>
</ns:Products>


---------------------------------------------------- But this is the OUTPUT that I get (note the name dupes): ---------------------------------------------------- <ns:Products xmlns:ns="http://w.ns.c/ns/prod/"> <ns:Product> <ns:Names> <ns:name>Bill</ns:name> <ns:name>Bill</ns:name> </ns:Names> </ns:Product> <ns:Product> <ns:Names> <ns:name>Sam</ns:name> <ns:name>Ron</ns:name> <ns:name>Sam</ns:name> <ns:name>Ron</ns:name> </ns:Names> </ns:Product> <ns:Product> <ns:Names> <ns:name>Ron</ns:name> <ns:name>Sam</ns:name> <ns:name>Joe</ns:name> <ns:name>Sam</ns:name> </ns:Names> </ns:Product> </ns:Products>

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar  get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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.