Let's say I have a table in SQL Server which contains the results of a query with an inner join.
The following XQuery:
select @code.query
(
'for $s in /root/row
return
<Foo Language="{data($s/@lang)}" Method="{data($s/@method)}" Returns="{data($s/@returnType)}">
<Bar ReferencedBy="{data($s/@callers)}" Static="{data($s/@static)}" />
</Foo>'
)
And its result:
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Baz" Static="true" />
</Foo>
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Bar" Static="false" />
</Foo>
What I would like in fact is the following:
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Baz" Static="true" />
<Bar ReferencedBy="Bar" Static="false" />
</Foo>
What's the best way to do this using XQuery in order to avoid resorting to LINQ and a hash table?