Note that there are some explanatory texts on larger screens.

plurals
  1. POXQuery if statement
    text
    copied!<p>I have problem with XQuery. I've spend on this proble a lot of time, and I can't make it work :( Here is my XML book node:</p> <pre><code> &lt;book id="bk101"&gt; &lt;author&gt;Gambardella, Matthew&lt;/author&gt; &lt;title&gt;XML Developer's Guide&lt;/title&gt; &lt;genre&gt;Computer&lt;/genre&gt; &lt;price&gt;44.95&lt;/price&gt; &lt;publish_date&gt;2000-10-01&lt;/publish_date&gt; &lt;description&gt;An in-depth look at creating applications with XML.&lt;/description&gt; &lt;/book&gt; </code></pre> <p>That's what i want to achive:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;XML Developer's Guide&lt;/b&gt; &lt;/td&gt; &lt;td class="author"&gt;Gambardella, Matthew&lt;/td&gt; &lt;td class="genre"&gt;Computer&lt;/td&gt; &lt;td class="price"&gt;44.95&lt;/td&gt; &lt;td class="priceVat"&gt;55.29&lt;/td&gt; &lt;td class="publish_date"&gt;2000-10-01&lt;/td&gt; &lt;td class="description"&gt;An in-depth look at creating applications with XML.&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>And here is my XQuery code:</p> <pre><code>for $book in doc("/home/kuba/mgr/pliki/books.xml")//book order by number($book/price) descending return &lt;tr&gt; &lt;td&gt;&lt;b&gt;{ string($book/title) }&lt;/b&gt;&lt;/td&gt; { for $value in $book/* return if($value != $book/title and name($value) != 'price') then &lt;td class="{name($value)}"&gt;{$value/text()}&lt;/td&gt; else if(name($value) = 'price') then &lt;td class="{name($value)}"&gt;{$value/text()}&lt;/td&gt; &lt;td class="{name($value)}Vat"&gt;{$value/text()*1.23}&lt;/td&gt; else () } &lt;/tr&gt; </code></pre> <p>The problem is in this line:</p> <pre><code> &lt;td class="{name($value)}Vat"&gt;{$value/text()*1.23}&lt;/td&gt; </code></pre> <p>Here is my error message:</p> <pre><code>Engine name: Saxon-PE XQuery 9.5.0.2 Severity: fatal Description: XPST0003: expected "else", found name "class" Start location: 17:0 URL: http://www.w3.org/TR/xpath20/#ERRXPST0003 </code></pre> <p>How i can make it? Is possible to format number in XQuery 1.0, i read that th is not possible but I want to make sure :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload