This seems to work:

let $results :=
<results>
    <name>Test</name>
    <date>01-Oct-2009</date>
    <interface>
         <id>ID 1</id>
         <address>2345</address>
    </interface>
    <interface>
         <id>ID 2</id>
         <address>3456</address>
    </interface>
    <interface>
         <id>ID 3</id>
         <address>6789</address>
    </interface>
    <interface>
         <id>ID 4</id>
         <address>7890</address>
    </interface>
</results>

return
  <item>
    {
    for $interface in $results/interface
      return
        <if>
          {
            $results/name,
            $results/date,
            $interface/id,
            $interface/address
          }
        </if>
    }
  </item>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Tony Mariella
Sent: Thursday, October 01, 2009 8:03 AM
To: [email protected]
Subject: [MarkLogic Dev General] Format XML Results

I have a query in Marklogic that returns results.
The query works fine. But I need to format the results so that I can out them 
into a table.

Here's what each document looks like when it is loaded into ML:

<results>
    <name>Test</name>
    <date>01-Oct-2009</date>
    <interface>
         <id>ID 1</id>
         <address>2345</address>
    </interface>
    <interface>
         <id>ID 2</id>
         <address>3456</address>
    </interface>
    <interface>
         <id>ID 3</id>
         <address>6789</address>
    </interface>
    <interface>
         <id>ID 4</id>
         <address>7890</address>
    </interface>
</results>

Here's what I want tthe output to look like when I return it from my query:

<item>
    <if>
       <name>Test</name>
       <date>01-Oct-2009</date>
       <id>ID 1</id>
       <address>2345</address>
    </if>
    <if>
       <name>Test</name>
       <date>01-Oct-2009</date>
       <id>ID 2</id>
       <address>3456</address>
    </if>
    <if>
       <name>Test</name>
       <date>01-Oct-2009</date>
       <id>ID 3</id>
       <address>6789</address>
    </if>
    <if>
       <name>Test</name>
       <date>01-Oct-2009</date>
       <id>ID 4</id>
       <address>7890</address>
    </if>
</item>

How can I format the output correctly ?

Tony Mariella






 NOTICE: This email message is for the sole use of the intended recipient(s) 
and may contain confidential and privileged information. Any unauthorized 
review, use, disclosure or distribution is prohibited. If you are not the 
intended recipient, please contact the sender by reply email and destroy all 
copies of the original message.


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to