Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I fix ugly XQuery output?
    primarykey
    data
    text
    <p>Here is my XML document:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="student.xsl"?&gt; &lt;Students xmlns="www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.example.com student.xsd"&gt; &lt;Student&gt; &lt;SSN&gt;622-12-5748&lt;/SSN&gt; &lt;Name&gt; &lt;First-Name&gt;Alexander&lt;/First-Name&gt; &lt;Last-Name&gt;Mart&lt;/Last-Name&gt; &lt;/Name&gt; &lt;Age&gt;26&lt;/Age&gt; &lt;Institution&gt;UCSF&lt;/Institution&gt; &lt;Email&gt;Alexander@yahoo.com&lt;/Email&gt; &lt;/Student&gt; &lt;/Students&gt; </code></pre> <p>I have this XQuery:</p> <pre><code>xquery version "1.0"; declare namespace xsd = "http://www.w3.org/2001/XMLSchema"; declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; declare default element namespace "http://www.example.com"; for $s in doc("student.xml")/Students/Student let $firstName := $s/First-Name let $lastName := $s/Last-Name let $email := $s/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>The output I am getting is:</p> <pre><code>&lt;row xmlns="http://www.example.com"&gt; &lt;first-name&gt; &lt;First-Name 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:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;Mart&lt;/Last-Name&gt; &lt;/last-name&gt; &lt;email&gt; &lt;Email 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>All the examples I see, though, output something like this:</p> <pre><code>&lt;row&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> <p>How do I format my output prettily like this?</p> <p>Also, why am I getting this</p> <pre><code>&lt;First-Name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; </code></pre> <p>tag in my results, instead of just <code>&lt;first-name&gt;</code>? Is there a way to get rid of that? I added the <code>declare default element namespace "http://www.example.com";</code> near the top because I couldn't get my XQuery to work without it. But it would be really nice if that wasn't getting displayed in my results.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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