English 中文(简体)
XQuery - Sequences
  • 时间:2024-12-22

XQuery - Sequences


Previous Page Next Page  

持有量是订购的物品集,物品可以类似或不同类型。

Creating a Sequence

产生频率时使用括号,在引文中加插或翻版和编号。 也可以将XML要素用作顺序的项目。

XQuery Expression

let $items := ( orange , <apple/>, <fruit type="juicy"/>, <vehicle type="car">sentro</vehicle>, 1,2,3, a , b ,"abc")
let $count := count($items)
return
<result>
   <count>{$count}</count>
   
   <items>
      {
	     for $item in $items
         return <item>{$item}</item>
      }
   </items>
   
</result>

Output

<result>
   <count>10</count>
   <items>
      <item>orange</item>
      <item>
         <apple/>
      </item>
      <item>
         <fruit type="juicy"/>
      </item>
      <item>
         <vehicle type="car">Sentro</vehicle>
      </item>
      <item>1</item>
      <item>2</item>
      <item>3</item>
      <item>a</item>
      <item>b</item>
      <item>abc</item>
   </items>
</result>

Viewing the Items of a Sequence

序列项目可采用指数或数值,按顺序排列。 以上例子将顺序排列的项目逐个。 让我们看到其他两种行动方式。

XQuery Expression (Index)

let $items := (1,2,3,4,5,6)
let $count := count($items)
return
   <result>
      <count>{$count}</count>
      
      <items>
      {
         for $item in $items[2]
         return <item>{$item}</item>
      }
      </items>
      
   </result>

Output

<result>
   <count>6</count>
   <items>
      <item>2</item>
   </items>
</result>

XQuery Expression (Value)

let $items := (1,2,3,4,5,6)
let $count := count($items)
return
   <result>
      <count>{$count}</count>
      
      <items>
      {
         for $item in $items[. = (1,2,3)]
         return <item>{$item}</item>
      }
      </items>
      
   </result>

Output

<result>
   <count>6</count>
   <items>
      <item>1</item>
      <item>2</item>
      <item>3</item>
   </items>
</result>
Advertisements