Tony,

Try something like this (assuming the <results> element is stored in a variable 
called $results):

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

Depending on how your query works, it would probably be more efficient to do 
the reformatting in the query instead of after it, but this should get you 
started at least.

Doug Glidden
Software Engineer
The Boeing Company
[email protected]



  _____

From: [email protected] 
[mailto:[email protected]] On Behalf Of Tony Mariella
Sent: Thursday, October 01, 2009 10:03
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









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

Reply via email to