How To Eliminate multi Entries in XSL--Please Help

Here should go questions about transforming XML with XSLT and FOP.
xp_pratibha
Posts: 4
Joined: Sat Jun 11, 2005 2:25 pm

How To Eliminate multi Entries in XSL--Please Help

Post 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
:?:
xp_pratibha
Posts: 4
Joined: Sat Jun 11, 2005 2:25 pm

Post 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>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
xp_pratibha
Posts: 4
Joined: Sat Jun 11, 2005 2:25 pm

Post 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
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
xp_pratibha
Posts: 4
Joined: Sat Jun 11, 2005 2:25 pm

Post by xp_pratibha »

Hi George,

Thank you So Much :-)

It helped me a lot.

Thanks again.

Regards,
X.P.Pratibha
Post Reply