我有以下 xml 文档
<Root>
<Translation>
<Entry language ="ES" text = "Alsace"/>
<Entry language ="DE" text = "Elsass"/>
<Entry language ="EN" text = "Alsace"/>
</Translation>
<Translation>
<Entry language ="ES" text = "Brittany"/>
<Entry language ="DE" text = "Bretagne"/>
<Entry language ="EN" text = "Brittany"/>
</Translation>
</Root>
我需要把它切碎成一张桌子,同时保留这些组。因此,由于翻译元素缺少任何 id 属性,因此分组是隐含在结构中的。
表格结果应如下所示。
translation_id, lanuage, text
---------------------------------
1,ES, Alsace
1,DE, Elsass
1,EN, Alsace
2,ES , Brittany
2,DE, Bretagne
2,EN Brittany
我尝试过各种各样的事情,比如
select newid(),
( select rows.n.value('(@language)[1]', 'nvarchar(max)')
from @p.nodes('/Translation/Entry') rows(n)
)
from @p.nodes('/Translation') rows(n)
但似乎无法在不使用某种循环的情况下获取分组 ID。
谢谢