How to return directory (Xquery path) as a value and not as a string of that path?

246 views Asked by At

When writing this code for 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>

It returns this:

<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>

How to return "2004-03-21" "2004-05-05", Instead of $g/occupies/@from $g/occupies/@to ?

1

There are 1 answers

0
John On BEST ANSWER

Try this. Missing {} in the return for first_day and last_day. Sample XML structure would be of great help, as suggested by @dirkk

<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>