XPathで忘れがちなこと
パス式内での軸の使用 - preceding-sibling
軸
preceding-sibling
軸に()
使うときもい。
※註: eXistでクエリー投げても下記の結果にはなりません。あくまで仕様上の話。
data1.xml
<abc> <x>1</x> <x>2</x> <def> <x>3</x> <x>4</x> <x>5</x> <x>6</x> </def> <x>7</x> <x>8</x> <def> <x>9</x> <x>10</x> </def> </abc>
chap3-11.xq
fn:doc("data1.xml")//x[4]/(preceding-sibling::x)[1]
結果
<x>1</x> <x>3</x>
シーケンスの先頭から数えてる! ()
がないと、
fn:doc("data1.xml")//x[4]/preceding-sibling::x[1]
当然こうなる。
<x>5</x> <x>7</x>
(preceding-sibling::)
きもいよー;;