如何将目录(Xquery路径)作为值返回而不是作为该路径的字符串?

时间:2014-11-17 15:22:02

标签: xquery where nodes clause basex

为Basex编写此代码时

<tourism>
{
  for $hotel in doc("tourism.xml")/tourism/hotel
  let $r:=$hotel/room
  let $g:=doc("tourism.xml")/tourism/guest
  where $g/@name="Udo Lindenberg" and $g/customer/@hotel=$hotel/@id and $r/@id=$g/occupies/@room
  return
    <hotel>
        <hotel_name>{string($hotel/@name)}</hotel_name>
          <first_day>$g/occupies/@from</first_day>
          <last_day>$g/occupies/@to</last_day>
    </hotel>
}
</tourism>

它返回:

<tourism>
  <hotel>
    <hotel_name>Interconti</hotel_name>
    <first_day>$g/occupies/@from</first_day>
    <last_day>$g/occupies/@to</last_day>
  </hotel>
  <hotel>
    <hotel_name>Tourist Inn</hotel_name>
    <first_day>$g/occupies/@from</first_day>
    <last_day>$g/occupies/@to</last_day>
  </hotel>

如何回归&#34; 2004-03-21&#34; &#34; 2004-05-05&#34;,而不是$ g /占用/ @从$ g /占用/ @到?

1 个答案:

答案 0 :(得分:3)

试试这个。在returnfirst_day的{​​{1}}中缺少{}。正如@dirkk

所建议的,XML结构示例将会有很大帮助
last_day