|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Trouble removing dup elements based on attributes
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.
<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>
<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>
_________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








