質問

Below is the sample structure of 2 XML DBs -

Subject DB

<Subjects>
 <Subject>Physics</Subject>
 <Subject>Biology</Subject>
 <Subject>Maths</Subject>
 <Subject>Algebra</Subject>
</Subjects>

Classification DB

<Classification>
 <Subject>Physics</Subject>
 <Subject>English</Subject>
 <Subject>History</Subject>
 <Subject>Algebra</Subject>
</Classification>

I need to have the distinct values from both the DBs as a single output and that too ordered like-

 <Subject>Algebra</Subject>
 <Subject>Biology</Subject>
 <Subject>English</Subject>
 <Subject>History</Subject>
 <Subject>Maths</Subject>
 <Subject>Physics</Subject>
役に立ちましたか?

解決

Well after little bit of trial and error, I was able to get the required output -

let $items := ( doc("Subject")//Topic , doc("Classification")//Topic )
for $x in distinct-values($items )
   order by $x
   return <Subject>{$x}</Subject>

I was confused where to put the distinct-values() and how to get two documents open in one stroke.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top