Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Select Unique

Reply
Thread Tools

Select Unique

 
 
Mystagogue
Guest
Posts: n/a
 
      12-11-2007
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?
 
Reply With Quote
 
 
 
 
TOUDIdel
Guest
Posts: n/a
 
      12-11-2007

Uzytkownik "Mystagogue" <(E-Mail Removed)> napisal w wiadomosci
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      12-12-2007

Mystagogue <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> <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.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-12-2007
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/
 
Reply With Quote
 
Pavel Lepin
Guest
Posts: n/a
 
      12-12-2007

Martin Honnen <(E-Mail Removed)> wrote in
<475fccbf$0$17536$(E-Mail Removed)-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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a unique method in python to unique a list? Token Type Python 9 09-09-2012 02:13 PM
list question... unique values in all possible unique spots ToshiBoy Python 6 08-12-2008 05:01 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
Issue with SELECT TOP 3 / UNIQUE MePadre ASP General 1 12-15-2003 01:34 PM
DataTable.Select not unique among users?? Kris Rudin ASP .Net 2 08-18-2003 09:57 PM



Advertisments