Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, your exact query shouldn't be producing that output. You must be using this instead (because of the <strong>default namespace declaration on your input</strong>):</p> <pre><code>declare namespace xsd = "http://www.w3.org/2001/XMLSchema"; declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; declare namespace x = "www.example.com"; declare default element namespace "http://www.example.com"; for $s in /x:Students/x:Student let $firstName := $s/x:Name/x:First-Name let $lastName := $s/x:Name/x:Last-Name let $email := $s/x:Email order by $lastName ascending return &lt;row&gt; &lt;first-name&gt; { $firstName } &lt;/first-name&gt; &lt;last-name&gt; { $lastName } &lt;/last-name&gt; &lt;email&gt; { $email } &lt;/email&gt; &lt;/row&gt; </code></pre> <p>That indeed output:</p> <pre><code>&lt;row xmlns="http://www.example.com"&gt; &lt;first-name&gt; &lt;First-Name xmlns="www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;Alexander&lt;/First-Name&gt; &lt;/first-name&gt; &lt;last-name&gt; &lt;Last-Name xmlns="www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;Mart&lt;/Last-Name&gt; &lt;/last-name&gt; &lt;email&gt; &lt;Email xmlns="www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;Alexander@yahoo.com&lt;/Email&gt; &lt;/email&gt; &lt;/row&gt; </code></pre> <p><strong>WHY?</strong>: Because your sequence constructor <code>{ $firstName }</code> output the node instace referenciated by <code>$firstName</code> not its string-value. That should be:</p> <pre><code>declare namespace x = "www.example.com"; declare default element namespace "http://www.example.com"; for $s in /x:Students/x:Student let $firstName := $s/x:Name/x:First-Name let $lastName := $s/x:Name/x:Last-Name let $email := $s/x:Email order by $lastName ascending return &lt;row&gt; &lt;first-name&gt; { $firstName/string() } &lt;/first-name&gt; &lt;last-name&gt; { string($lastName) } &lt;/last-name&gt; &lt;email&gt; { normalize-space($email) } &lt;/email&gt; &lt;/row&gt; </code></pre> <p>Output:</p> <pre><code>&lt;row xmlns="http://www.example.com"&gt; &lt;first-name&gt;Alexander&lt;/first-name&gt; &lt;last-name&gt;Mart&lt;/last-name&gt; &lt;email&gt;Alexander@yahoo.com&lt;/email&gt; &lt;/row&gt; </code></pre>
 

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