472,796 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 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 2652

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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.