Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Target
XPath to map data into.

Examples

The query example below demonstrates the general FLWOR structure in XQuery. It basically below basically gathers data from forms, instances and workitems associatively and returns them in a desired format.

Code Block
languagexml
titleXQuery Example
collapsetrue
for $i in /Instance

let $formNo := ($i/Number)
let $instance := unordered($i[Number=$formNo])[last()]
let $workItemId := unordered($instance/WorkItems/WorkItem/Id)[last()]
let $formDataId:= $i/WorkItems/WorkItem[last()]/DataId
let $form := form[data(@Id)=$formDataId]/PoolRoot

where 
($fNo = '' or ($formNo/text() = $fNo))
and ($startDate = '' or  ($i/Start >= $startDate))
and ($endDate = '' or  ($i/End <= $endDate)) 
and ($state = '' or ($i/State/text() = $state))
and ($department = '' or ($form/Departman/Id = $department))

order by $i/Start/text() descending

return 
<Result>
	<FormNo>{$i/Number/text()}</FormNo>
	<DocId>{$workItemId/text()}</DocId>
	<State>{$i/State/text()}</State>
	<StartDate>{$i/Start/text()}</StartDate>
	<EndDate>{$i/End/text()}</EndDate>
	<InitiatedBy>{$i/WorkItems/WorkItem[1]/CompletedBy/@Caption/string()}</InitiatedBy>
	<Subject>{$form/Konu/text()}</Subject>
	<File>{$form/Dosyalar/Dosya/Id/text()}</File>
</Result>

We This example demonstrates the general FLWOR structure in XQuery, so we can read this the query as the following:

  • For expression loops over Instance nodes that are located on root level and assigns them to parameter $i
  • Let expression gathers several information depending on instance, workitem and form data
  • Where expression applies criteria on the data. Control parameters used in this section are declared in Parameters section on the same window.
  • Order expression orders the result according to the given value
  • Result expression returns the result data in the specified XML format

...