XPath functions and operators
A subset of the XML Path Language (XPath) 2.0 is implemented in IBM® Business Monitor and the IBM Business Monitor development toolkit.
The following tables show the symbols, operators, terminal symbols, and functions of XPath 2.0 that are supported by Business Monitor and the Business Monitor development toolkit. For more information about XPath 2.0, including the complete syntax in Extended Backus-Naur Form (EBNF), see http://www.w3.org/TR/xpath20/.
Supported symbols
| Number | Symbol | Consists of | Expression |
|---|---|---|---|
| [1] | XPath | ::= | Expr |
| [2] | Expr | ::= | ExprSingle |
| [3] | ExprSingle | ::= | IfExpr | OrExpr |
| [7] | IfExpr | ::= | "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
| [8] | OrExpr | ::= | AndExpr ( "or" AndExpr )* |
| [9] | AndExpr | ::= | ComparisonExpr ( "and" ComparisonExpr )* |
| [10] | ComparisonExpr | ::= | RangeExpr ( (ValueComp | GeneralComp) RangeExpr )? |
| [11] | RangeExpr | ::= | AdditiveExpr |
| [12] | AdditiveExpr | ::= | MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )* |
| [13] | MultiplicativeExpr | ::= | UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )* |
| [14] | UnionExpr | ::= | IntersectExceptExpr |
| [15] | IntersectExceptExpr | ::= | InstanceofExpr |
| [16] | InstanceofExpr | ::= | TreatExpr |
| [17] | TreatExpr | ::= | CastableExpr |
| [18] | CastableExpr | ::= | CastExpr |
| [19] | CastExpr | ::= | UnaryExpr |
| [20] | UnaryExpr | ::= | ("-" | "+")* ValueExpr |
| [21] | ValueExpr | ::= | PathExpr |
| [22] | GeneralComp | ::= | "=" | "!=" | "<" | "<=" | ">" | ">=" |
| [23] | ValueComp | ::= | "eq" | "ne" | "lt" | "le" | "gt" | "ge" |
| [25] | PathExpr | ::= | ("/" RelativePathExpr?) | RelativePathExpr |
| [26] | RelativePathExpr | ::= | StepExpr (("/") StepExpr)* |
| [27] | StepExpr | ::= | FilterExpr | AxisStep |
| [28] | AxisStep | ::= | (ReverseStep | ForwardStep) |
| [29] | ForwardStep | ::= | AbbrevForwardStep |
| [31] | AbbrevForwardStep | ::= | NodeTest |
| [32] | ReverseStep | ::= | AbbrevReverseStep |
| [34] | AbbrevReverseStep | ::= | ".." |
| [35] | NodeTest | ::= | NameTest |
| [36] | NameTest | ::= | QName |
| [38] | FilterExpr | ::= | PrimaryExpr |
| [41] | PrimaryExpr | ::= | Literal | ParenthesizedExpr | ContextItemExpr | FunctionCall |
| [42] | Literal | ::= | NumericLiteral | StringLiteral |
| [43] | NumericLiteral | ::= | IntegerLiteral | DecimalLiteral |
| [46] | ParenthesizedExpr | ::= | "(" Expr? ")" |
| [47] | ContextItemExpr | ::= | "." |
| [48] | FunctionCall | ::= | QName "(" (ExprSingle ("," ExprSingle)*)? ")" |
Additional support for inbound and outbound events
To refer to inbound and outbound events specifically, use the following paths.
InboundEventDefinitionRef '/' 'predefinedData' '/' (
'creationTime'|'elapsedTime'|'extensionName'|'globalInstanceId'|
'localInstanceId'|'msg'|'priority'|'repeatCount'|'sequenceNumber'|
'severity'|'version')
InboundEventDefinitionRef '/' 'propertyData' '/' ContextDataElementName
InboundEventDefinitionRef '/' 'extendedData' '/' ExtendedDataElementName (
'/' ExtendedDataElementName)*
InboundEventDefinitionRef '/' EventPartId '/' Expr
- InboundEventDefinitionRef is a path to an event entry point or exit point in a monitoring context definition hierarchy. The path can include the IDs of nested monitoring context definitions, dot (".") or dot dot (".."). It must have as its last step one and only one ID of an inbound event definition. For example, itemContext/outOfStockEvent.
- ContextDataElementName is the name of a context data element defined by the Common Base Event type of the referenced event entry or exit point. The pertinent Common Base Event event type definition is referenced using the extensionName attribute.
- ExtendedDataElementName is the name of an extended data element defined by the Common Base Event type of the referenced event entry or exit point. The pertinent event type definition is referenced via the extensionName attribute.
- EventPartId is the ID of an event part defined for the referenced event entry or exit point.
- Expr is a path into an inbound or outbound event data structure, which is appended to the path defined for the event part referenced by EventPartId. For paths into inbound events, Table 2 applies. For paths into outbound events (that is, the left sides of assignments to outbound event fields), Table 3 applies. Furthermore, the numeric predicates that are used to construct sequences in outbound events must have no gaps and must be ascending at every nesting level. A step without a numeric predicate is equivalent to one followed by [1].
| Symbol | Expression |
|---|---|
| Expr | UnionExpr | FunctionName '(' UnionExpr ')' |
| FunctionName | 'fn:count' | 'fn:avg' | 'fn:max' | 'fn:min' | 'fn:sum' |
| UnionExpr | PathExpr ('|' PathExpr)* |
| PathExpr | (StepExpr '/')* (StepExpr | ('@' | 'attribute::') AttrNameTest | ('child::')? 'text()') |
| StepExpr | ('.' | ('child::')? NameTest) ('[' PredicateExpr ']')* |
| NameTest | QName | '*' | NCName ':' '*' |
| AttrNameTest | NameTest | '*' ':' NCName |
| PredicateExpr | OrExpr | Digits |
| OrExpr | AndExpr ('or' AndExpr)* |
| AndExpr | BooleanExpr ('and' BooleanExpr)* |
| BooleanExpr | '(' OrExpr ')' | ValueExpr GeneralComp ValueExpr | ('@' | 'attribute::') AttrNameTest |
| GeneralComp | '=' | '!=' | '<' | '<=' | '>' | '>=' |
| ValueExpr | ('@' | 'attribute::') AttrNameTest | Literal |
| Literal | NumericLiteral | StringLiteral |
| StringLiteral | ('"' (EscapeQuot | [^"])* '"') | ("'" (EscapeApos | [^'])* "'") |
| NumericLiteral | IntegerLiteral | DecimalLiteral | DoubleLiteral |
| IntegerLiteral | [+-]? Digits |
| DecimalLiteral | [+-]? ('.' Digits) | (Digits '.' [0-9]*) |
| DoubleLiteral | [+-]? (('.' Digits) | (Digits ('.' [0-9]*)?)) [eE] [+-]? Digits |
| EscapeQuot | '""' |
| EscapeApos | "''" |
| Digits | [0-9]+ |
| Symbol | Expression |
|---|---|
| Expr | PathExpr |
| PathExpr | (StepExpr '/')* ( StepExpr | '@' AttrNameTest ) |
| StepExpr | NameTest ('[' Digits ']')? |
| NameTest | QName |
| AttrNameTest | NameTest |
| Digits | [0-9]+ |
Supported operators
| Number | Operator |
|---|---|
| 3 | if |
| 4 | or |
| 5 | and |
| 6 | eq, ne, lt, le, gt, ge, =, !=, <, <=, >, >= |
| 8 | +, - |
| 9 | *, div, idiv, mod |
| 16 | -(unary), +(unary) |
| 18 | / |
| 19 | ( ) |
For operands that are not null, the value comparison operators (ne, lt, le, gt, ge) and the general comparison operators (=, !=, <, <=, >, >=) behave identically. If one or both operands are null (empty sequences) however, a value comparison a returns null value, while a general comparison returns a value of false.
Supported terminal symbols
| Number | Symbol | Consists of | Expression |
|---|---|---|---|
| [71] | IntegerLiteral | ::= | Digits |
| [72] | DecimalLiteral | ::= | ("." Digits) | (Digits "." [0-9]*) |
| [74] | StringLiteral | ::= | ("'" (EscapeApos | [^'])* "'") |
| [76] | EscapeApos | ::= | " '' " |
Accessing elements within lists
myEvent/myEventPart/theOrder/item[12]/price
fn:sum(myEvent/myEventPart/theOrder/item/price)
For
more information, see Aggregate
functions.Supported constructor functions
- xs:boolean($arg as xs:boolean?) as xs:boolean?
- xs:boolean($arg as xs:integer?) as xs:boolean?
- xs:boolean($arg as xs:decimal?) as xs:boolean?
- xs:boolean($arg as xs:string?) as xs:boolean?
- xs:integer($arg as xs:boolean?) as xs:integer?
- xs:integer($arg as xs:integer?) as xs:integer?
- xs:integer($arg as xs:decimal?) as xs:integer?
- xs:integer($arg as xs:string?) as xs:integer?
- xs:decimal($arg as xs:boolean?) as xs:decimal?
- xs:decimal($arg as xs:integer?) as xs:decimal?
- xs:decimal($arg as xs:decimal?) as xs:decimal?
- xs:decimal($arg as xs:string?) as xs:decimal?
- xs:decimal($arg as xs:duration?) as xs:decimal?
- xs:string($arg as xs:boolean?) as xs:string?
- xs:string($arg as xs:integer?) as xs:string?
- xs:string($arg as xs:decimal?) as xs:string?
- xs:string($arg as xs:string?) as xs:string?
- xs:string($arg as xs:duration?) as xs:string?
- xs:string($arg as xs:dateTime?) as xs:string?
- xs:string($arg as xs:date?) as xs:string?
- xs:string($arg as xs:time?) as xs:string?
- xs:duration($arg as xs:string?) as xs:duration?
- xs:duration($arg as xs:duration?) as xs:duration?
- xs:duration($arg as xs:decimal?) as xs:duration?
- xs:dayTimeDuration($arg as xs:integer?) as xs:dayTimeDuration?
- xs:dayTimeDuration($arg as xs:decimal?) as xs:dayTimeDuration?
- xs:dayTimeDuration($arg as xs:string?) as xs:dayTimeDuration?
- xs:dayTimeDuration($arg as xs:duration?) as xs:dayTimeDuration?
- xs:dateTime($arg as xs:string?) as xs:dateTime?
- xs:dateTime($arg as xs:dateTime?) as xs:dateTime?
- xs:dateTime($arg as xs:date?) as xs:dateTime?
- xs:date($arg as xs:string?) as xs:date?
- xs:date($arg as xs:dateTime?) as xs:date?
- xs:date($arg as xs:date?) as xs:date?
- xs:time($arg as xs:string?) as xs:time?
- xs:time($arg as xs:dateTime?) as xs:time?
- xs:time($arg as xs:time?) as xs:time?
The Boolean constructor functions with numeric arguments return a value of true if the argument is non-zero and false if it is zero. The numeric constructor functions with a boolean argument return 1 if the argument is true and 0 if it is false. The integer constructor functions with a decimal argument discard any fractional part of the argument. The constructors converting between decimal and duration values map a day-time duration to its length in seconds (including any fractional seconds) and vice versa. All constructors with string arguments expect a valid lexical representation of the result data type. Constructor functions that return a string value return the canonical lexical representation of the argument. The dateTime constructor with a date argument returns the first instant of the given date.
Supported general functions
- fn:abs($arg as xs:integer?) as xs:integer?
- fn:abs($arg as xs:decimal?) as xs:decimal?
- fn:round($arg as xs:decimal?) as xs:decimal?
- fn:round($arg as xs:integer?) as xs:integer?
- fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?, ... ) as xs:string
- fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer?
- fn:substring($sourceString as xs:string?, $startingLoc as xs:integer) as xs:string
- fn:substring($sourceString as xs:string?, $startingLoc as xs:decimal) as xs:string
- fn:substring($sourceString as xs:string?, $startingLoc as xs:integer, $length as xs:integer) as xs:string
- fn:substring($sourceString as xs:string?, $startingLoc as xs:integer, $length as xs:decimal) as xs:string
- fn:substring($sourceString as xs:string?, $startingLoc as xs:decimal, $length as xs:integer) as xs:string
- fn:substring($sourceString as xs:string?, $startingLoc as xs:decimal, $length as xs:decimal) as xs:string
- fn:string-length($arg as xs:string?) as xs:integer?
- fn:upper-case($arg as xs:string?) as xs:string
- fn:lower-case($arg as xs:string?) as xs:string
- fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
- fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
- fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
- fn:true() as xs:boolean
- fn:false() as xs:boolean
- fn:not($arg as xs:boolean?) as xs:boolean
- fn:not($arg as xs:integer?) as xs:boolean
- fn:not($arg as xs:decimal?) as xs:boolean
- fn:not($arg as xs:string?) as xs:boolean
- fn:empty($arg as xs:anyAtomicType?) as xs:boolean
- fn:exists($arg as xs:anyAtomicType?) as xs:boolean
- fn:current-dateTime() as xs:dateTime
- fn:current-date() as xs:date
- fn:current-time() as xs:time
- fn:days-from-duration($arg as xs:duration?) as xs:integer?
- fn:hours-from-duration($arg as xs:duration?) as xs:integer?
- fn:minutes-from-duration($arg as xs:duration?) as xs:integer?
- fn:seconds-from-duration($arg as xs:duration?) as xs:decimal?
- fn:year-from-dateTime($arg as xs:dateTime?) as xs:integer?
- fn:month-from-dateTime($arg as xs:dateTime?) as xs:integer?
- fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer?
- fn:hours-from-dateTime($arg as xs:dateTime?) as xs:integer?
- fn:minutes-from-dateTime($arg as xs:dateTime?) as xs:integer?
- fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal?
- fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration?
- fn:year-from-date($arg as xs:date?) as xs:integer?
- fn:month-from-date($arg as xs:date?) as xs:integer?
- fn:day-from-date($arg as xs:date?) as xs:integer?
- fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration?
- fn:hours-from-time($arg as xs:time?) as xs:integer?
- fn:minutes-from-time($arg as xs:time?) as xs:integer?
- fn:seconds-from-time($arg as xs:time?) as xs:decimal?
- fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration?
- fn:adjust-dateTime-to-timezone($arg as xs:dateTime?) as xs:dateTime?
- fn:adjust-dateTime-to-timezone($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime?
- fn:adjust-date-to-timezone($arg as xs:date?) as xs:date?
- fn:adjust-date-to-timezone($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date?
- fn:adjust-time-to-timezone($arg as xs:time?) as xs:time?
- fn:adjust-time-to-timezone($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time?
- fn:count($arg as item()*) as xs:integer
- fn:avg($arg as xs:integer*) as xs:decimal?
- fn:avg($arg as xs:decimal*) as xs:decimal?
- fn:max($arg as xs:integer*) as xs:integer?
- fn:max($arg as xs:decimal*) as xs:decimal?
- fn:min($arg as xs:integer*) as xs:integer?
- fn:min($arg as xs:decimal*) as xs:decimal?
- fn:sum($arg as xs:integer*) as xs:integer?
- fn:sum($arg as xs:decimal*) as xs:decimal?
Aggregate functions
The five aggregate functions fn:count, fn:avg, fn:max, fn:min, and fn:sum (defined in http://www.w3.org/TR/xpath-functions/#aggregate-functions) are supported, provided that their argument references data in an inbound event. The argument of fn:count() can have any type. The other four functions must have numeric arguments.
For example, fn:sum(myEvent/extendedData/widgetList/widget/quantity) returns the total number of widgets in a list held in extended data elements.
fn:avg(myEvent/listOfItems/tns:item/@tns:cost) returns the average item cost in a list represented by the listOfItems event part.
Retrieving QName values
The value of an attribute or element in the event with a data type defined as xs:QName is retrieved as a string of the format: {namespaceName}localPart. The namespace name is obtained by resolving the QName's prefix, based on the namespace declarations in the event. For example, if the event contains the namespace declaration xmlns:app="http://www.my.com/my/application/namespace", the QName value app:customerRating would be retrieved as {http://www.my.com/my/application/namespace}customerRating.
Comparing time zones
- Both values must be associated with a time zone, OR
- Both values must not be associated with a time zone