At 2010-02-17 07:38 -0500, Tony Mariella wrote:
Looks like I was wrong..
When I use the distinct-nods local function:
declare function local:distinct-nodes ($arg as node()*) as node()*
{
let $result :=
for $a at $apos in $arg
where every $other in $arg except $a satisfies not(deep-equal($other,$a))
return $a
return if( count($result) = 0 ) then $arg[1] else $result
};
<results>
{ local:distinct-nodes( doc('tony.xml')/results/item ) }
</results>
My result looks like this:
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
</results>
I want it to look like this:
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
</results>
Interesting ... I just ran it again as I had in my original post to
you (though I confess for expediency I'm not using the MarkLogic
processor) and I get the results you want:
T:\ftemp>type tony.xml
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
</results>
T:\ftemp>xquery tony.xq
<?xml version="1.0" encoding="UTF-8"?>
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
</results>
T:\ftemp>type tony.xq
declare function local:distinct-nodes ($arg as node()*) as node()*
{
let $result :=
for $a at $apos in $arg
where every $other in $arg except $a satisfies not(deep-equal($other,$a))
return $a
return if( count($result) = 0 ) then $arg[1] else $result
};
<results>
{ local:distinct-nodes( doc('tony.xml')/results/item ) }
</results>
T:\ftemp>
If I add another group of tags like this:
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
</results>
This is what I want my result to look like:
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
</results>
Why are you including the "Tall Rd" entry when it is not a
singleton? There are three "Tall Rd" entries and they are
identical. I understood you to want only those items that are not
duplicated elsewhere. Because they are duplicates, I get the same
result as with the first dataset:
T:\ftemp>type tony2.xml
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal/>
</item>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
<item>
<addr>55 Tall Rd</addr>
<city>Orlando</city>
<state>FL</state>
<testVal/>
</item>
</results>
T:\ftemp>xquery tony2.xq
<?xml version="1.0" encoding="UTF-8"?>
<results>
<item>
<addr>24 Short Rd</addr>
<city>Baltimore</city>
<state>MD</state>
<testVal>TEST1</testVal>
</item>
</results>
T:\ftemp>type tony2.xq
declare function local:distinct-nodes ($arg as node()*) as node()*
{
let $result :=
for $a at $apos in $arg
where every $other in $arg except $a satisfies not(deep-equal($other,$a))
return $a
return if( count($result) = 0 ) then $arg[1] else $result
};
<results>
{ local:distinct-nodes( doc('tony2.xml')/results/item ) }
</results>
T:\ftemp>
Can you please clarify your requirement and state why you think the
"Tall Rd" entry belongs in the result?
. . . . . . . . . . . . Ken
--
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30
Vote for your XML training: http://www.CraneSoftwrights.com/q/i/
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman mailto:[email protected]
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general