about the oxf:xquery processor

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

about the oxf:xquery processor

Alexander Žaťko
I spent some quality time figuring out how to use the undocumented (as
far as I can tell) oxf:xquery processor. I am summarizing my findings
below.

1) place your xquery code into the input element of the oxf:xquery
processor. Optionally you can reference a file from your disc
2) do not include XML prolog (the <?xml version="1.0"
encoding="utf-8"?> thing) if you place the code directly into the
<input> element.
3) escape all brackets in your code with &lt; and &gt; entities
4) make sure to wrap your code into <document></document> elements and
declare all of the namespaces as shown below.

The <inpu name="data" t> element points to the XML to be transformed by
this processor.

A complete example is shown below:

     <p:processor name="oxf:xquery">
<!-- optionally you can refer to an on-disc file that may include the
XML prolog line.
         <p:input name="config"
href="oxf:/examples/iEDI/massageOutput.xquery"/>
-->
         <p:input name="config">
             <document
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline"
                 xmlns:saxon="http://saxon.sf.net/"
xsi:type="xs:string">&lt;headers&gt;
                 {
                 for $c at $colPos in /porder/detail[1]/*
                 let $colName := name($c)
                 let $d := data(/porder/detail/*[$colPos])
                 return
                 element {$colName} {$d}
                 }
                 &lt;/headers&gt;</document>
         </p:input>
         <p:input name="data" href="#porder-result"/>
         <p:output name="data" id="xquery-output"/>
     </p:processor>


A corresponding referenced file would look like this:

<?xml version="1.0" encoding="utf-8"?>
<document
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:oxf="http://www.orbeon.com/oxf/processors"
     xmlns:p="http://www.orbeon.com/oxf/pipeline"
     xmlns:saxon="http://saxon.sf.net/"
xsi:type="xs:string">&lt;headers&gt;
{
for $c at $colPos in /porder/detail[1]/*
let $colName := name($c)
let $d := data(/porder/detail/*[$colPos])
return
element {$colName} {$d}
}
&lt;/headers&gt;</document>




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: about the oxf:xquery processor

Erik Bruchez
Administrator
Alexander,

 > I spent some quality time figuring out how to use the undocumented
 > (as far as I can tell) oxf:xquery processor. I am summarizing my
 > findings below.
 >
 > 1) place your xquery code into the input element of the oxf:xquery
 > processor. Optionally you can reference a file from your disc

Correct. But also check the XQuery Processor section here:

http://www.orbeon.com/ops/doc/home-changes-30

   Query format. In addition to XQuery code embedded into XML, the
   XQuery processor now supports in its config input a text document
   of the form:

   <document xsi:type="xs:string">xquery version "1.0"; ...  </document>

 > 2) do not include XML prolog (the <?xml version="1.0" encoding="utf-8"?>
 > thing) if you place the code directly into the <input> element.

Correct.

 > 3) escape all brackets in your code with &lt; and &gt; entities

Correct too.

It should be noted that there is as of yet no reasonable XML embedding
standard for XQuery. So we just devised our own, so you don't have to
escape all the opening brackets for elements, for example. This has
some limitations though, so when that doesn't work you should use the
"Text Document" OPS format.

   http://www.orbeon.com/ops/doc/reference-formats#text-documents

 > 4) make sure to wrap your code into <document></document> elements and
 > declare all of the namespaces as shown below.

In fact the root element should be:

o <xquery> when using OPS XQuery embedding.

o <document> when following the "Text Document" OPS format.

 > The <inpu name="data" t> element points to the XML to be transformed by
 > this processor.

Correct.

Great analysis!

It is planned to fully document the XQuery processor in 3.0 final.

-Erik



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws