繁体   English   中英

返回 xquery 的元素和元素计数

[英]Returning an element and count of element for an xquery

我是 xquery 的新手,我的任务是获取每个讲师分配了多少部分列表的列表。

因此,例如,我想返回一个包含讲师的列表和 course_listings 的计数。

我已经为以下 xml 尝试过类似的操作。

for $x in doc(course.xml")/root/course_listing/section_listing
return $x//instructor//count(instructor_listing)

任何帮助,将不胜感激。

<root>
<course_listing>
  <note>#</note>
  <course>216-088</course>
  <title>NEW STUDENT ORIENTATION</title>
  <credits>0</credits>
  <level>U</level>
  <restrictions>; ; REQUIRED OF ALL NEW STUDENTS. PREREQ: NONE</restrictions>
   <section_listing>
      <section_note></section_note>
      <section>Se 001</section>
      <days>W</days>
      <hours>
          <start>1:30pm</start>
          <end></end>
      </hours>
      <bldg_and_rm>
          <bldg>BUS</bldg>
          <rm>S230</rm>
      </bldg_and_rm>
      <instructor>Gusavac</instructor>
      <comments>9 WKS BEGINNING WEDNESDAY, 9/6/00 </comments>
   </section_listing>
   <section_listing>
      <section_note></section_note>
      <section>Se 002</section>
      <days>F</days>
      <hours>
          <start>11:30am</start>
          <end></end>
      </hours>
      <bldg_and_rm>
          <bldg>BUS</bldg>
          <rm>S171</rm>
      </bldg_and_rm>
      <instructor>Gusavac</instructor>
      <comments>9 WKS BEGINNING FRIDAY, 9/8/00 </comments>
   </section_listing>
</course_listing>

<course_listing>
  <note>#</note>
  <course>216-293</course>
  <title>BUSINESS ETHICS</title>
  <credits>3</credits>
  <level>U</level>
  <restrictions>; ; PREREQ: NONE</restrictions>
   <section_listing>
      <section_note></section_note>
      <section>Se 001</section>
      <days>R</days>
      <hours>
          <start>2:30pm</start>
          <end>5:10pm</end>
      </hours>
      <bldg_and_rm>
          <bldg>BUS</bldg>
          <rm>S230</rm>
      </bldg_and_rm>
      <instructor>Silberg</instructor>
   </section_listing>
</course_listing>
</root>

通常这是通过分组来完成的:

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method 'text';
declare option output:item-separator '&#10;';


for $section in //section_listing
group by $instructor := $section/instructor
return $instructor || ': ' || count($section/parent::course_listing)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM