Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

removing duplicates

 
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an xml as follows:
<root>
<index name="XYZ"/>
<index name="ABC"/>
<index name="XYZ"/>
</root>
I have to print XYZ and ABC i.e. i should ingore duplicates for 'name' attribute. Could anyone tell me how to do this using xsl??
Regards,
shankar
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the following stylesheet to get rid of duplicate name entries.
It should work with any standards compliant XSLT processor, but I verified it only on Apache's Xalan.
Hope this helps . . .
Shashank

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:template match="index[not(./@name = preceding::index/@name)]">
<xsl:value-of select="@name"/>
</xsl:template>
</xsl:stylesheet>
[ February 28, 2002: Message edited by: Shashank M Tanksali ]
 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanx for the reply. It worked with xalan for me too. But I want to do a client side transformation. I am using IE 5.5 and it does not work over there.Any help ??
Regards,
shankar.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it using IE5.5, it worked.
To use IE5.5 for styling xml documents you must install Microsoft XSL plug-in (MSXML3.0). The following are the instructions to set up MSXML3.0
*********************************************
The following instructions are from Roger's xsl tutorial at xfront.com:
Download xmlinst.exe from http://msdn.microsoft.com/msdn-files/027/001/469/xmlinst.exe
Double click on the downloaded file. This will result in extracting some files.
Open a DOS window. Change directory to where you placed the extracted files. Set the path
environment variable to include the directory where regsvr32.exe is located (on Windows 98 it is
on c:\windows\system, on WIN2000 it is C:\WINNT\system32) Then type the following commands:
xmlinst
regsvr32 msxml3.dll
***********************************************
IE is ready to use for transforming XML documents

Note: There's a new version of XML parser MSXML4.0. I had problems setting it up, so I am using MSXML3.0. It'd be great if someone could tell me how to install and use MSXML4.0 for transforming XML docs.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic