Description:
Evaluates one or more XQueries against the content of a FlowFile. The results of those XQueries are assigned to FlowFile Attributes or are written to the content of the FlowFile itself, depending on configuration of the Processor. XQueries are entered by adding user-defined properties; the name of the property maps to the Attribute Name into which the result will be placed (if the Destination is ‘flowfile-attribute’; otherwise, the property name is ignored). The value of the property must be a valid XQuery. If the XQuery returns more than one result, new attributes or FlowFiles (for Destinations of ‘flowfile-attribute’ or ‘flowfile-content’ respectively) will be created for each result (attributes will have a ‘.n’ one-up number appended to the specified attribute name). If any provided XQuery returns a result, the FlowFile(s) will be routed to ‘matched’. If no provided XQuery returns a result, the FlowFile will be routed to ‘unmatched’. If the Destination is ‘flowfile-attribute’ and the XQueries matche nothing, no attributes will be applied to the FlowFile.
Tags:
XML, evaluate, XPath, XQuery
Properties:
In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values.
Name | Default Value | Allowable Values | Description |
Destination | flowfile-content |
* flowfile-content * flowfile-attribute |
Indicates whether the results of the XQuery evaluation are written to the FlowFile content or a FlowFile attribute. If set to <flowfile-content>, only one XQuery may be specified and the property name is ignored. If set to <flowfile-attribute> and the XQuery returns more than one result, multiple attributes will be added to theFlowFile, each named with a '.n' one-up number appended to the specified attribute name |
Output: Method | XML |
* XML * HTML * text |
Identifies the overall method that should be used for outputting a result tree. |
Output: Omit XML Declaration | false | Specifies whether the processor should output an XML declaration when transforming a result tree. | |
Output: Indent | false | Specifies whether the processor may add additional whitespace when outputting a result tree. |
Dynamic Properties:
Dynamic Properties allow the user to specify both the name and value of a property.
Name | Value | Description |
A FlowFile attribute(if <Destination> is set to 'flowfile-attribute' | An XQuery | If <Destination>='flowfile-attribute' then the FlowFile attribute is set to the result of the XQuery. If <Destination>='flowfile-content' then the FlowFile content is set to the result of the XQuery. |
Relationships:
Name | Description |
matched | FlowFiles are routed to this relationship when the XQuery is successfully evaluated and the FlowFile is modified as a result |
unmatched | FlowFiles are routed to this relationship when the XQuery does not match the content of the FlowFile and the Destination is set to flowfile-content |
failure | FlowFiles are routed to this relationship when the XQuery cannot be evaluated against the content of the FlowFile. |
Reads Attributes:
None specified.
Writes Attributes:
Name | Description |
user-defined | This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute . |
Examples:
This processor produces one attribute or FlowFile per XQueryResult. If only one attribute or FlowFile is desired, the following examples demonstrate how this can be achieved using the XQuery language. The examples below reference the following sample XML:
<table border="1" cellspacing="0">
<tr>
<td>
<?xml version="1.0" encoding="UTF-8"?><br>
<?xml-stylesheet type="text/xsl" href="foo.xsl"?><br>
<ns:fruitbasket xmlns:ns="http://namespace/1"><br>
<fruit taste="crisp"><br>
<!-- Apples are my favorite--><br>
<name>apple</name><br>
<color>red</color><br>
</fruit><br>
<fruit><br>
<name>apple</name><br>
<color>green</color><br>
</fruit><br>
<fruit><br>
<name>banana</name><br>
<color>yellow</color><br>
</fruit><br>
<fruit taste="sweet"><br>
<name>orange</name><br>
<color>orange</color><br>
</fruit>v
<fruit><br>
<name>blueberry</name></br>
<color>blue</color></br>
</fruit></br>
<fruit taste="tart"><br>
<name>raspberry</name><br>
<color>red</color><br>
</fruit><br>
<fruit><br>
<name>none</name><br>
<color/><br>
</fruit><br>
</ns:fruitbasket><br>
</tr>
</td>
</table>
- XQuery to return all “fruit” nodes individually (7 Results):
- //fruit
- //fruit
- XQuery to return only the first “fruit” node (1 Result):
- //fruit[1]
- //fruit[1]
- XQuery to return only the last “fruit” node (1 Result):
- //fruit[count(//fruit)]
- //fruit[count(//fruit)]
- XQuery to return all “fruit” nodes, wrapped in a “basket” tag (1 Result):
- <basket>{//fruit}</basket>
- <basket>{//fruit}</basket>
- XQuery to return all “fruit” names individually (7 Results):
- //fruit/text()
- //fruit/text()
- XQuery to return only the first “fruit” name (1 Result):
- //fruit[1]/text()
- //fruit[1]/text()
- XQuery to return only the last “fruit” name (1 Result):
- //fruit[count(//fruit)]/text()
- //fruit[count(//fruit)]/text()
- XQuery to return all “fruit” names as a comma separated list (1 Result):
- string-join((for $x in //fruit return $x/name/text()), ‘, ‘)
- string-join((for $x in //fruit return $x/name/text()), ‘, ‘)
- XQuery to return all “fruit” colors and names as a comma separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘, ‘)
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘, ‘)
- XQuery to return all “fruit” colors and names as a comma separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘, ‘)
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘, ‘)
- XQuery to return all “fruit” colors and names as a new line separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘\n’)
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ‘ ‘)) return $y), ‘\n’)