I have the following SQL
with X(x) as (select 'a' union select 'b' )
, Y(y) as (select 1 union select 2 union select 3)
select x, y from X cross join Y
for xml path('')
and it returns
<x>a</x>
<y>1</y>
<x>a</x>
<y>2</y>
<x>a</x>
<y>3</y>
<x>b</x>
<y>1</y>
<x>b</x>
<y>2</y>
<x>b</x>
<y>3</y>
Is it possible to make it returns
<a><y>1</y><y>2</y><y>3</y></a>
<b><y>1</y><y>2</y><y>3</y></b>
or
<x v="a"><y>1</y><y>2</y><y>3</y></x>
<x v="b"><y>1</y><y>2</y><y>3</y></x>
Or maybe I should do the permutation using xquery FLWOR?