Page 1 of 1

XQuery syntax problem

Posted: Sat Oct 28, 2017 3:46 pm
by R0bin_
Hello! Im having some issues figuring out some syntax using an if-if else in an loop. What am I doing wrong? Thanks :D

Code: Select all

{for $programme in $tv/programme
return
<div class="channel_programmes">
   <span class="programme_time">
      {data($programme/start)}
   </span>
   <span class="programme_title">
      {data($programme/title)}
   </span>   
   let $x := {data($programme/type)};
   return            
   if ($x = 'movie') then
      (<span class="movie">Film</span>)
   else if($x = 'series') then
      (<span class="series">Serie</span>)
   else if($x = 'sports') then
      (<span class="tvshow">Tv show</span>)
   else if($x = 'tvshow') then
      (<span class="sports">Sport</span>)
</div>
}


Best regards,
R0bin_

Re: XQuery syntax problem

Posted: Mon Oct 30, 2017 10:39 am
by adrian
Hi,

What's the issue?
The snippet is out of context, so the best I can do is this:

Code: Select all

{
for $programme in $tv/programme
return
<div class="channel_programmes">
   <span class="programme_time">
      {data($programme/start)}
   </span>
   <span class="programme_title">
      {data($programme/title)}
   </span>   
   {
   let $x := data($programme/type)
   return           
   if ($x = 'movie') then
      (<span class="movie">Film</span>)
   else if($x = 'series') then
      (<span class="series">Serie</span>)
   else if($x = 'sports') then
      (<span class="tvshow">Tv show</span>)
   else if($x = 'tvshow') then
      (<span class="sports">Sport</span>)
   else ()
   }
</div>
}

I'm assuming $tv is declared somewhere...

PS: You seem to have switched "tvshow" with "sports", but then again I don't know what's the desired result.

Regards,
Adrian