У меня есть XML-документ Библии
как
<bookcoll>
<book>
<bktshort>Matthew</bktshort>
<chapter><chtitle>Chapter 1</chtitle>
<v>The book of the generation of Jesus Christ, the son of David, the son of Abraham.
</v>
<v>Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judas and his brethren;
</v>
..
</chapter>
<chapter><chtitle>Chapter 2</chtitle>
<v>Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, there came wise men from the east to Jerusalem,
</v>
Я хотел бы сохранить номер строки общего числа <v>
узлов.
Этот оператор сбрасывает номер для каждого узла главы
select
Chapter.value('../../bktshort[1]', 'varchar(200)'),
Replace(Chapter.value('../chtitle[1]', 'varchar(200)'),'Chapter ', ''),
p.number,
Chapter.value('.','varchar(max)')
from
master..spt_values p
CROSS APPLY
@xml.nodes('/bookcoll/book/chapter/v[position()=sql:column("number")]') T(Chapter)
--where p.type = 'p'
order by
Chapter.value('../../bktshort[1]', 'varchar(200)'),
Replace(Chapter.value('../chtitle[1]', 'varchar(200)'),'Chapter ', ''),
p.number
так вместо
Matthew 1 23 Behold, a virgin shall be with child, and shall bring forth a son, and they shall call his name Emmanuel, which being interpreted is, God with us.
Matthew 1 24 Then Joseph being raised from sleep did as the angel of the Lord had bidden him, and took unto him his wife:
Matthew 1 25 And knew her not till she had brought forth her firstborn son: and he called his name JESUS.
Matthew 2 1 Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, there came wise men from the east to Jerusalem,
Matthew 2 2 Saying, Where is he that is born King of the Jews? for we have seen his star in the east, and are come to worship him.
Я бы хотел
Matthew 1 23 Behold, a virgin shall be with child, and shall bring forth a son, and they shall call his name Emmanuel, which being interpreted is, God with us.
Matthew 1 24 Then Joseph being raised from sleep did as the angel of the Lord had bidden him, and took unto him his wife:
Matthew 1 25 And knew her not till she had brought forth her firstborn son: and he called his name JESUS.
Matthew 2 <b>26</b> Now when Jesus was born in Bethlehem of Judaea in the days of Herod the king, behold, there came wise men from the east to Jerusalem,
Matthew 2 <b>27</b> Saying, Where is he that is born King of the Jews? for we have seen his star in the east, and are come to worship him.
Примечание: я знаю, что таблица spt_values
недостаточно велика и должна использовать локальную таблицу.