473,382 Members | 1,752 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,382 software developers and data experts.

Select Unique

Given XML like this...

<stuff>
<thing id="1" result="true"/>
<thing id="2" result="true"/>
<thing id="3" result="false"/>
<thing id="4" result="false"/>
<thing id="5" result="error"/>
</stuff>

Is there an XPath statement that will select only *unique* "@result"
samples? For example, given the above, I'd like to have "thing"
results that consist only of id 1, 3 and 5, because id 2 and 4 are
duplicate result types. Anybody?
Dec 11 '07 #1
4 2681

Uzytkownik "Mystagogue" <ba****@axiscode.comnapisal w wiadomosci
news:72**********************************@18g2000h sf.googlegroups.com...
Given XML like this...

<stuff>
<thing id="1" result="true"/>
<thing id="2" result="true"/>
<thing id="3" result="false"/>
<thing id="4" result="false"/>
<thing id="5" result="error"/>
</stuff>

Is there an XPath statement that will select only *unique* "@result"
samples? For example, given the above, I'd like to have "thing"
results that consist only of id 1, 3 and 5, because id 2 and 4 are
duplicate result types. Anybody?
In my opinion quite good way is using "attributes features". It does mean in
one element you may have attributes only with unique names. For example:

<xsl:apply-templates select=//@*/>
....
<xsl:template match="@*">
<xsl:attribute name="{.}">whatever</xsl:attribute>
</xsl:template>

Result: element with attributes done from unigue (distinct) values

--
td
xmlguru.net
Dec 11 '07 #2

Mystagogue <ba****@axiscode.comwrote in
<72**********************************@18g2000hsf.g ooglegroups.com>:
<stuff>
<thing id="1" result="true"/>
<thing id="2" result="true"/>
<thing id="3" result="false"/>
<thing id="4" result="false"/>
<thing id="5" result="error"/>
</stuff>

Is there an XPath statement that will select only *unique*
"@result" samples?
Not possible with pure XPath1. In XPath2:

for $a in /stuff/* return
if (not($a/preceding-sibling::*[@result=$a/@result]))
then $a
else /..

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
Dec 12 '07 #3
Mystagogue wrote:
Given XML like this...

<stuff>
<thing id="1" result="true"/>
<thing id="2" result="true"/>
<thing id="3" result="false"/>
<thing id="4" result="false"/>
<thing id="5" result="error"/>
</stuff>

Is there an XPath statement that will select only *unique* "@result"
samples?
Yes:
/stuff/thing[not(@result = preceding-sibling::thing/@result)]

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '07 #4

Martin Honnen <ma*******@yahoo.dewrote in
<47***********************@newsspool4.arcor-online.net>:
Mystagogue wrote:
><stuff>
<thing id="1" result="true"/>
<thing id="2" result="true"/>
<thing id="3" result="false"/>
<thing id="4" result="false"/>
<thing id="5" result="error"/>
</stuff>

Is there an XPath statement that will select only
*unique* "@result" samples?

/stuff/thing[not(@result =
preceding-sibling::thing/@result)]
Well, I'll be damned. It's been a year and a half and I
still miss clever but essentially simple tricks like that.

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
Dec 12 '07 #5

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

Similar topics

1
by: MePadre | last post by:
To all, I am hoping for some insight in to this query. I have a homepage on my Intranet that displays the three most recent postings for a number of categories (i.e. announcements, discussion...
0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
9
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my...
4
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the...
5
by: Antanas | last post by:
Hi folks. I need unique sequence object generated for each row returned form select statement. Here is my ADDID() UDF: CREATE FUNCTION DB2ADMIN.ADDID() RETURNS CHAR(6) NOT DETERMINISTIC F1:...
2
by: Marcel Hug | last post by:
Hi NG! With a Inner-Join SQL I get my datas in a DataSet. In the table are the column Entry and Version. Like this: Entry Version 1 1 1 2 1 ...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
0
by: kaapie | last post by:
Oracle does not know which table's rowid to return from this view and thus it gives an error. What this means is that one of the underlying tables in the view has to have either a primary key or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.