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[(_at_)name='Names']/rs/row">
<xsl:if test="not(@firstname =
preceding::attrib[(_at_)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[(_at_)name='Names']/rs/row"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template mode="XXX" match="attrib[(_at_)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/
--~------------------------------------------------------------------
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>
--~--