EvaluateXQuery 2.0.0

Bundle
org.apache.nifi | nifi-standard-nar
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, XPath, XQuery, evaluate
Input Requirement
REQUIRED
Supports Sensitive Dynamic Properties
false
  • Additional Details for EvaluateXQuery 2.0.0

    EvaluateXQuery

    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:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="foo.xsl"?>
    <ns:fruitbasket xmlns:ns="http://namespace/1">
        <fruit taste="crisp">           <!-- Apples are my favorite-->
            <name>apple</name>
            <color>red</color>
        </fruit>
        <fruit>
            <name>apple</name>
            <color>green</color>
        </fruit>
        <fruit>
            <name>banana</name>
            <color>yellow</color>
        </fruit>
        <fruit taste="sweet">
            <name>orange</name>
            <color>orange</color>
        </fruit>
        <fruit>
            <name>blueberry</name>
            <color>blue</color>
        </fruit>
        <fruit taste="tart">
            <name>raspberry</name>
            <color>red</color>
        </fruit>
        <fruit>
            <name>none</name>
            <color/>
        </fruit>
    </ns:fruitbasket>
    
    • XQuery to return all “fruit” nodes individually (7 Results):

      • //fruit]
    • XQuery to return only the first “fruit” node (1 Result):

      • //fruit[1]
    • XQuery to return only the last “fruit” node (1 Result):

      • //fruit[count(//fruit)]
    • XQuery to return all “fruit” nodes, wrapped in a “basket” tag (1 Result):

      • {//fruit}
    • XQuery to return all “fruit” names individually (7 Results):

      • //fruit/text()
    • XQuery to return only the first “fruit” name (1 Result):

      • //fruit[1]/text()
    • XQuery to return only the last “fruit” name (1 Result):

      • //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()), ‘, ‘)
    • 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), ‘, ‘)
    • 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), ‘, ‘)
    • 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’)
Properties
Dynamic Properties
System Resource Considerations
Resource Description
MEMORY Processing requires reading the entire FlowFile into memory
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.
Writes Attributes
Name Description
user-defined This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute .