Page 1 of 1

How To Eliminate multi Entries in XSL--Please Help

Posted: Sat Jun 11, 2005 2:28 pm
by xp_pratibha
Hi All ,
I am a newbie to XSL . I am not sure where I am going wrong ?

My XML Data is like this and it has multiple duplicate entries:

<Employees>
<Accountant>
<Employee name="varsha">
<Empdetails id="100" age="23"/>
<comment/>
<Empaddress addr="sdlklklk"/>
</Employee>
</Accountant>
</Employees>

The only thing that is unique is "id".I need to eliminate the duplicate entries based on this...

Here goes my XSL :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml-stylesheet type="text/xsl" href="xslt_example_param.xsl"?>
<xsl:output method="text" />
<xsl:template match="/Employees/Accountant">
<xsl:for-each select="Employee/Empdetails[not(@id= preceding-sibling::FirewallRule/@id)]">
<xsl:value-of select="@id"/><xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I couldn't find what is wrong with my XSL ...Can anyone please help me to solve this or any alternate solution.

Thanks,
Pratibha
:?:

Posted: Sat Jun 11, 2005 2:33 pm
by xp_pratibha
Hi one correction :here is the XSL I used..Please help me..Thanks.

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml-stylesheet type="text/xsl" href="xslt_example_param.xsl"?>
<xsl:output method="text" />
<xsl:template match="/Employees/Accountant">
<xsl:for-each select="Employee/Empdetails[not(@id= preceding-sibling::Employee/Empdetails/@id)]">
<xsl:value-of select="@id"/><xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Posted: Sat Jun 11, 2005 8:07 pm
by george
Hi,
Employees/Accountant">
<xsl:for-each select="Employee/Empdetails[not(@id= preceding-sibling::Employee/Empdetails/@id)]
The problem seems to be the fact that you are looking for preceding siblings of the Empdetails node, and that has no Employee sibling, you shold go one step up to the parent of Empdetails and there look for preceding siblings:

Code: Select all


Employees/Accountant">
<xsl:for-each select="Employee/Empdetails[not(@id= ../preceding-sibling::Employee/Empdetails/@id)]
(not tested)

Hope that helps,
George

Posted: Sun Jun 12, 2005 12:17 pm
by xp_pratibha
Thanks George ...

But Still its not working even after in-corporating ur changes.
I need one clarification ..Can I use preceding-siblings on attribute axis.
I read if I use preceding-sibling on attribute axis it will be empty. Is this apply to my case.

Is there any alternative to perform this ??

Thanks again George.

Thanks,
Pratibha

Posted: Mon Jun 13, 2005 10:23 am
by george
Hi Pratibha,

Here it is a funtional sample:

Code: Select all


<Employees>
<Accountant>
<Employee name="varsha">
<Empdetails id="100" age="23"/>
<comment/>
<Empaddress addr="sdlklklk"/>
</Employee>

<Employee name="varsha">
<Empdetails id="101" age="23"/>
<comment/>
<Empaddress addr="sdlklklk"/>
</Employee>

<Employee name="varsha">
<Empdetails id="100" age="23"/>
<comment/>
<Empaddress addr="sdlklklk"/>
</Employee>


</Accountant>
</Employees>

Code: Select all


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml-stylesheet type="text/xsl" href="xslt_example_param.xsl"?>
<xsl:output method="text"/>
<xsl:template match="/Employees/Accountant">
<xsl:for-each select="Employee/Empdetails[not(@id= ../preceding-sibling::Employee/Empdetails/@id)]">
<xsl:value-of select="@id"/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
gives as output:

Code: Select all


100
101
Best Regards,
George

Posted: Wed Jun 15, 2005 3:51 pm
by xp_pratibha
Hi George,

Thank you So Much :-)

It helped me a lot.

Thanks again.

Regards,
X.P.Pratibha