473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Solution for avoiding duplicates?

I think I've come up with a solution for avoid duplicates in a
nodeset. The sticky part was that with a nodeset, you can't use axes
(such as preceding-sibling) because those only refer to the source
tree. However, I was able to exploit the fact that generate-id
returns a unique id.

Consider the following XML document:

<?xml version="1.0" encoding="utf-8"?>
<root>

<RiskCodes id="1">
<RiskCode id="1.1">A</RiskCode>
<RiskCode id="1.2">B</RiskCode>
<RiskCode id="1.3">A</RiskCode>
</RiskCodes>
<RiskCodes id="2">
<RiskCode id="2.1">A</RiskCode>
<RiskCode id="2.2">C</RiskCode>
</RiskCodes>

</root>

And here is the stylesheet I use to print out non-duplicate RiskCodes:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" indent="yes" xalan:indent-amount="3"/>

<xsl:template match="/">
<xsl:variable name="vNodes" select="/root/RiskCodes"/>

<xsl:for-each select="$vNodes/RiskCode">
<xsl:variable name="vNode" select="."/>

<xsl:if test="generate-id($vNode)=generate-id($vNodes/RiskCode[.=$vNode][1])">
<xsl:copy-of select="$vNode"/>
</xsl:if>

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The resulting output is shown here:

<?xml version="1.0" encoding="UTF-8"?>
<RiskCode id="1.1">A</RiskCode>
<RiskCode id="1.2">B</RiskCode>
<RiskCode id="2.2">C</RiskCode>

I'm posting this because when I searched for a soution online, I found
none. Hopefully this will help others. Mind you, this is probably
pretty slow. If anyone has any better ideas, I'd be glad to hear
them.

Regards,
Brian.
Jul 20 '05 #1
0 1178

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert | last post by:
Im a beginner in PHP and Im having a problem with this code. Im trying to remove duplicate elements from an array created via $_GET. I want users to be able to click on a link which sends an email...
5
by: Les Juby | last post by:
maybe this is a real Newbie Question but I'm sure I got around this in the past but can't remember how. If a form is situated in normal HTML then a paragraph tag is inserted after the Submit...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
10
by: Tim Mulholland | last post by:
My company is about to begin working on an ASP.NET application. There are going to be two primary developers working on this project. It will be a fairly deep project (lots of lines of code) but...
11
by: google_groups3 | last post by:
Hi all. I currently have 2 text files which contain lists of file names. These text files are updated by my code. What I want to do is be able to merge these text files discarding the...
4
by: Frank-René Schäfer | last post by:
-- A class needs to have N members according to N types mentioned in a typelist (possibly with one type occuring more than once). -- The classes should be generated **avoiding** multiple...
4
by: ryushinyama | last post by:
I had to do a lot of searching to get this one to work and in doing so I saw a lot of different sites where people were looking for this answer so I thought I would put it up. If you are trying...
8
by: preeny8 | last post by:
Hi guys, So I'm editing an existing database (Access 2003), and I need a bit of help in making a validation rule. My table has many fields, 3 of which are indexed (location, number & revision) ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.