[MarkLogic Dev General] Format XML Results

David Scott Gurney gurneyds at ldschurch.org
Thu Oct 1 07:30:41 PDT 2009


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: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Tony Mariella
Sent: Thursday, October 01, 2009 8:03 AM
To: general at developer.marklogic.com
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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20091001/04370470/attachment-0001.html


More information about the General mailing list