473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Eliminating duplicate information in selected sorted rows

Can somebody help me with this please...

I have an xml file along the lines of

<results>
<result status="Pass">
<person name="Fred"/>
<subject name="English" />
</result>
<result status="Pass">
<person name="Harry"/>
<subject name="Maths" />
</result>
<result status="Fail">
<person name="Fred"/>
<subject name="History" />
</result>
<result status="Fail">
<person name="Harry"/>
<subject name="English" />
</result>
<result status="Pass">
<person name="Fred"/>
<subject name="Maths" />
</result>
<result status="Pass">
<person name="Harry"/>
<subject name="History" />
</result>
</results>

And need to generate html for all result staus="Passes" sorted and displayed
like this:

Passes:
Name Subject
------ --------
Fred English
- Maths
Harry History
- Maths

My best attempt so far is:

....
<xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<tr>
<td>
<xsl:value-of select="person/@name"/>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each>
....

Which gives:

Passes:
Name Subject
------ --------
Fred English
Fred Maths
Harry History
Harry Maths

The problems as I see it are that the output is a sub-set af the whole data,
and it is sorted.

Any ideas on how to remove the duplicate entries in the first column would
be very welcome.

--
Matt

Oct 7 '05 #1
6 1495
Ixa
> <xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<tr>
<td>
<xsl:value-of select="person/@name"/>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each> [...] Any ideas on how to remove the duplicate entries in the first column
would be very welcome.


One suggestion:

---8<---8<---
<xsl:variable name="name" select="person/@name"/>
<xsl:if test="not(prece ding::person[@name = $name])">
<xsl:value-of select="person/@name"/>
</xsl:if>
---8<---8<---

--
Ixa

Oct 8 '05 #2
"Ixa" <ix*@niksula.hu t.fi> wrote in message
news:43******** *************** @news.fv.fi...
<xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<tr>
<td>
<xsl:value-of select="person/@name"/>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each>

[...]
Any ideas on how to remove the duplicate entries in the first column
would be very welcome.


One suggestion:

---8<---8<---
<xsl:variable name="name" select="person/@name"/>
<xsl:if test="not(prece ding::person[@name = $name])">
<xsl:value-of select="person/@name"/>
</xsl:if>
---8<---8<---


Thanks for the suggestion. I tried it but got blanks for *every* line.

--
Matt
Oct 8 '05 #3
Ixa
> Thanks for the suggestion. I tried it but got blanks for *every* line.

Hmm, I get the expected result. Here's the script that I used:

---8<---8<---
<xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<tr>
<td>
<xsl:variable name="name" select="person/@name"/>
<xsl:if test="not(prece ding::person[@name = $name])">
<xsl:value-of select="person/@name"/>
</xsl:if>
</td>
<td>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each>
---8<---8<---

and the result (name once in first column and all passed items in
second column):

---8<---8<---
<tr>
<td>Fred</td>
<td>English</td>
</tr>
<tr>
<td></td>
<td>Maths</td>
</tr>
<tr>
<td>Harry</td>
<td>Maths</td>
</tr>
<tr>
<td></td>
<td>History</td>
</tr>
---8<---8<---

--
Ixa

Oct 8 '05 #4
"Ixa" <ix*@niksula.hu t.fi> wrote in message
news:43******** *************** @news.fv.fi...
Thanks for the suggestion. I tried it but got blanks for *every* line.


Hmm, I get the expected result. Here's the script that I used:

....
I tried again, and got these results - the script is after (sorry for the
length)...
With all the data in place:
Dick Geography
Dick History
Harry English
Harry French
Harry Maths
Tom English
Tom Maths
Processing person names:
Geography
History
English
French
Harry Maths
English
Tom Maths
xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="report.xs l"?>
<report>
<results>
<result status="Pass">
<subject name="Maths"/>
<person name="Tom" />
</result>
<result status="Fail">
<subject name="Maths"/>
<person name="Dick" />
</result>
<result status="Pass">
<subject name="Maths"/>
<person name="Harry" />
</result>
<result status="Fail">
<subject name="History"/>
<person name="Tom" />
</result>
<result status="Pass">
<subject name="History"/>
<person name="Dick" />
</result>
<result status="Fail">
<subject name="History"/>
<person name="Harry" />
</result>
<result status="Pass">
<subject name="English"/>
<person name="Tom" />
</result>
<result status="Fail">
<subject name="English"/>
<person name="Dick" />
</result>
<result status="Pass">
<subject name="English"/>
<person name="Harry" />
</result>
<result status="Fail">
<subject name="Geography "/>
<person name="Tom" />
</result>
<result status="Pass">
<subject name="Geography "/>
<person name="Dick" />
</result>
<result status="Fail">
<subject name="Geography "/>
<person name="Harry" />
</result>
<result status="Pass">
<subject name="French"/>
<person name="Harry" />
</result>
</results>
</report>

xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/report">
<html>
<body>
<table border="1">
<xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<xsl:sort select="subject/@name"/>
<tr>
<td>
<xsl:value-of select="person/@name"/>
</td>
<td>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each>
</table>
<table border="1">
<xsl:for-each select="results/result[@status='Pass']">
<xsl:sort select="person/@name"/>
<xsl:sort select="subject/@name"/>
<tr>
<td>
<xsl:variable name="name" select="person/@name"/>
<xsl:if test="not(prece ding::person[@name = $name])">
<xsl:value-of select="person/@name"/>
</xsl:if> 
</td>
<td>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

--
Matt
Oct 8 '05 #5
Ixa
> I tried again, and got these results - the script is after

So the sorting confuses the tests and another approach might be better.
Here's one (search for unique persons and their successful results, not
vice versa):

---8<---8<---
<table border="1">
<xsl:for-each select="//person/@name">
<xsl:sort/>
<xsl:variable name="name" select="."/>
<xsl:variable name="items"
select="/report/results/result[person[@name = $name] and
@status='Pass']"/>
<xsl:if test="not(prece ding::person[@name = $name])">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:for-each select="$items" >
<xsl:sort select="subject/@name"/>
<xsl:if test="position( ) = 1">
<xsl:value-of select="subject/@name"/>
</xsl:if>
</xsl:for-each>
</td>
</tr>
<xsl:for-each select="$items" >
<xsl:sort select="subject/@name"/>
<xsl:if test="position( ) &gt; 1">
<tr>
<td/>
<td>
<xsl:value-of select="subject/@name"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</table>
---8<---8<---

--
Ixa

Oct 8 '05 #6
"Ixa" <ix*@niksula.hu t.fi> wrote in message
news:43******** *************** @news.fv.fi...
I tried again, and got these results - the script is after


So the sorting confuses the tests and another approach might be better.
Here's one (search for unique persons and their successful results, not
vice versa):


Lateral thinking - I love it! It works great!

Thanks for your trouble :-)

--
Matt
Oct 8 '05 #7

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

Similar topics

9
2313
by: Paul | last post by:
Can anyone suggest an efficient way to eliminate duplicate entries in a list? The naive approach below works fine, but is very slow with lists containing tens of thousands of entries: def uniq(list): u = for x in list: if x not in u: u.append(x) return u
5
2071
by: gordy | last post by:
edit: this came out longer than I thought, any comments about anything here is greatly appreciated. thank you for reading My system stores millions of records, each with fields like firstname, lastname, email address, city, state, zip, along with any number of user defined fields. The application allows users to define message templates with variables. They can then select a template, and for each variable in the template, type in a...
1
1562
by: A.T. | last post by:
I have an XML document that looks like the following, except that it has about 30,000 entries. <root> <version id="A-0000"> <!many elements within- removed for ease of reading> </version> <version id="A-0000"> </version> <version id="A-0001"> </version>
7
23937
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have, for example, a list of town names, but there are hundreds of duplicates, like: "Aberdeen Aberdeen Aberdeen Edinburg Edinburg Inverness etc."
9
14589
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or FirstName/LastName/email? Or is it possible to allow this but to throw up an alert message? Warning that this person is probably already in the database? TIA
4
22394
by: Henry J. | last post by:
Can somebody tell me how to delete multiple rows in a datagridview selected by the user? I tried the following two methods to no avail. I have a myDataGridView that is bound to myDataTable's myDataView. The column "Name" is the primary key. I want to delete the rows selected by the user: foreach (DataGridViewRow drv in myDataGridView.SelectedRows) {
24
19918
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes with every renewal Renewals in 2004 would be D, 2005 S, and 2006 L. polexpdates for a given customer...
5
8431
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English: -------------------------------- -- Eliminating Duplicate rows -- -------------------------------- -- select all into a temp table. -- truncate origional table.
2
11601
by: cday119 | last post by:
Hi Everyone, So I have a datagridview and it has a column called status. It has 3 values: New, Printed, and Shipped. Now a user can select multiple rows and click "set to printed". I then do a foreach loop on datagridview.selectedrows and change the status to printed. Now the problem is that if the datagridview is sorted by status, when the status is changed from new to printed, that row is moved from being under new to printed and all...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.