Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在选择后更新xml中的位置索引_Sql Server_Xml_Tsql - Fatal编程技术网

Sql server 在选择后更新xml中的位置索引

Sql server 在选择后更新xml中的位置索引,sql-server,xml,tsql,Sql Server,Xml,Tsql,我有以下xml,当以最多三人一组的方式选择时,需要修改它们的索引值,以反映其在返回的xml中的新位置。我已经在这篇文章的底部写下了我需要的结果 <root> <document> <index>1</index> <text>stuff</text> </document> <document> <index>2</index> &l

我有以下xml,当以最多三人一组的方式选择时,需要修改它们的索引值,以反映其在返回的xml中的新位置。我已经在这篇文章的底部写下了我需要的结果

<root>
  <document>
    <index>1</index>
    <text>stuff</text>
  </document>
  <document>
    <index>2</index>
    <text>stuff</text>
  </document>
  <document>
    <index>3</index>
    <text>stuff</text>
  </document>
  <document>
    <index>4</index>
    <text>stuff</text>
  </document>
  <document>
    <index>5</index>
    <text>stuff</text>
  </document>
  <document>
    <index>6</index>
    <text>stuff</text>
  </document>
  <document>
    <index>7</index>
    <text>stuff</text>
  </document>
  <document>
    <index>8</index>
    <text>stuff</text>
  </document>
  <document>
    <index>9</index>
    <text>stuff</text>
  </document>
  <document>
    <index>10</index>
    <text>stuff</text>
  </document>
</root>

1.
东西
2.
东西
3.
东西
4.
东西
5.
东西
6.
东西
7.
东西
8.
东西
9
东西
10
东西
最多三组提取后

<root>
  <document>
    <index>1</index>
    <text>stuff</text>
  </document>
  <document>
    <index>2</index>
    <text>stuff</text>
  </document>
  <document>
    <index>3</index>
    <text>stuff</text>
  </document>
</root

<root>
  <document>
    <index>1</index>
    <text>stuff</text>
  </document>
  <document>
    <index>2</index>
    <text>stuff</text>
  </document>
  <document>
    <index>3</index>
    <text>stuff</text>
  </document>
</root

<root>
  <document>
    <index>1</index>
    <text>stuff</text>
  </document>
  <document>
    <index>2</index>
    <text>stuff</text>
  </document>
  <document>
    <index>3</index>
    <text>stuff</text>
  </document>
</root

<root>
  <document>
    <index>1</index>
    <text>stuff</text>
  </document>
</root

1.
东西
2.
东西
3.
东西

将查询返回的XML存储在变量中,并更新索引值

set @XMLTarget.modify('replace value of (/root/document/index/text())[1] with 1')
set @XMLTarget.modify('replace value of (/root/document/index/text())[2] with 2')
set @XMLTarget.modify('replace value of (/root/document/index/text())[3] with 3')

在生成的XML中,是否有一个包含所有元素的根节点?否。每个组都来自对原始XML执行的不同选择。