Xquery to get attribute name and type from a XSD schema?
<p>I was following a tutorial from marklogic,</p>

<p><a href="https://developer.marklogic.com/learn/2007-04-schema" rel="nofollow">https://developer.marklogic.com/learn/2007-04-schema</a></p>

<p>In a scenario, where I have xsd file</p>

<pre><code>    &lt;!-- tutorial.xsd --&gt;
&lt;xs:schema targetNamespace="http://marklogic.com/tutorial"
 attributeFormDefault="unqualified"
 elementFormDefault="unqualified"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xs:element name="name" type="xs:token"
   abstract="false" nillable="false"/&gt;
  &lt;xs:element name="qualification" type="xs:token"
   abstract="false" nillable="false"/&gt;
  &lt;xs:element name="born" type="xs:date"
   abstract="false" nillable="false"/&gt;
  &lt;xs:element name="dead" type="xs:date"
   abstract="false" nillable="false"/&gt;
  &lt;xs:element name="isbn" type="xs:unsignedLong"
   abstract="false" nillable="false"/&gt;
  &lt;xs:attribute name="id" type="xs:ID"/&gt;
  &lt;xs:attribute name="available" type="xs:boolean"/&gt;
  &lt;xs:attribute name="lang" type="xs:language"/&gt;
  &lt;xs:element name="title" abstract="false" nillable="false"&gt;
    &lt;xs:complexType mixed="false"&gt;
      &lt;xs:simpleContent&gt;
    &lt;xs:extension base="xs:token"&gt;
      &lt;xs:attribute ref="lang" use="optional"/&gt;
    &lt;/xs:extension&gt;
      &lt;/xs:simpleContent&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="library" abstract="false" nillable="false"&gt;
    &lt;xs:complexType mixed="false"&gt;
      &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt;
    &lt;xs:element ref="book" maxOccurs="unbounded" minOccurs="1"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="author" abstract="false" nillable="false"&gt;
    &lt;xs:complexType mixed="false"&gt;
      &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt;
    &lt;xs:element ref="name" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="born" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="dead" minOccurs="0" maxOccurs="1"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute ref="id" use="optional"/&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="book" abstract="false" nillable="false"&gt;
    &lt;xs:complexType mixed="false"&gt;
      &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt;
    &lt;xs:element ref="isbn" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="title" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="author" minOccurs="0"
   maxOccurs="unbounded"/&gt;
    &lt;xs:element ref="character" minOccurs="0"
   maxOccurs="unbounded"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute ref="id" use="optional"/&gt;
      &lt;xs:attribute ref="available" use="optional"/&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="character" abstract="false" nillable="false"&gt;
    &lt;xs:complexType mixed="false"&gt;
      &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt;
    &lt;xs:element ref="name" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="born" minOccurs="1" maxOccurs="1"/&gt;
    &lt;xs:element ref="qualification" minOccurs="1"
   maxOccurs="1"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute ref="id" use="optional"/&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
&lt;/xs:schema&gt;
</code></pre>

<p>I wanted to extract the attribute name and type from this xsd.
Following is my XQuery:</p>

<pre><code>if (xdmp:database-name(xdmp:database()) ne 'Schemas')
then error(
  QName('', 'NOT-SCHEMAS'), 'make sure the content-source is Schemas')
else
doc('tutorial.xsd')
  /descendant::xs:element/@name
(: results :)
</code></pre>

<p>I am getting the following:</p>

<pre><code>name
qualification
born
dead
isbn
title
library
author
book
character
</code></pre>

<p>but I need the attribute and the value together</p>

<pre><code>name xs:token
qualification xs:token
born xs:token
</code></pre>

<p>Can someone help me rewrite the Xquery to achive this above output?</p>