Select individual values ​​according to node child in XQuery

Say I have the following XML:

<info>
    <channel>
        <A>
          <X>
            <title>title1</title>
          </X>
          <Y value="20"/>
        </A>
    </channel>
    <channel>
        <A>
          <X>
            <title>title1</title>
          </X>
          <Y value="20"/>
        </A>
        <A>
          <X>
            <title>title2</title>
          </X>
          <Y value="20"/>
        </A>
    </channel>
</info>

and next xquery

{
for $A in doc('test.xml')//A
let $TITLE := $A/X/title
where string($A/Y/value) > 20
return
  string($TITLE)
}

these are of course the outputs:

title1
title1
title2

How can I use distinct-valuesto remove duplicates? Interesting, because foressentially it gives me only one element per iteration, and I cannot call distinct-valueson $A. Or is there another way to remove duplicate output?

The problem is that I need to refer to another node, so basically the call distinct-values(doc...)does not work, since it does not return nodes.

+5
source share
1 answer

UPDATE

xpath :

//A[index-of(//A/X/title, X/title)[1]]

A title s.

xpath, Y - XQuery FLWOR.

UPDATE END

distinct-values xpath, :

for $title in distinct-values(doc('test.xml')//A/X/@title)
return string($title)

distinct-values(doc('test.xml')//A/X/@title)
+5

All Articles