How To Eliminate multi Entries in XSL--Please Help

Here should go questions about transforming XML with XSLT and FOP.
xp_pratibha
Posts: 4

How To Eliminate multi Entries in XSL--Please Help

Sat Jun 11, 2005 2:28 pm

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

Sat Jun 11, 2005 2:33 pm

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: 2100

Sat Jun 11, 2005 8:07 pm

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

Sun Jun 12, 2005 12:17 pm

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: 2100

Mon Jun 13, 2005 10:23 am

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

Wed Jun 15, 2005 3:51 pm

Hi George,

Thank you So Much :-)

It helped me a lot.

Thanks again.

Regards,
X.P.Pratibha

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 1 guest