Template
Value resolver – Abstract
Purpose: This interprets a statically defined Template as a parameter, which can include the data of the print XML for the input value via XPath (1.0), and returns the result as a string.
See also: Parse XML
►IMPORTANT◄ The Template resolver is not available in client context (Client workflow, Client workflows).
The Template resolver interprets a static Template definition configured as the only parameter of the resolver, which may include references to data of the Print XML of the input value and returns an output string as a result:
Any serializable object can be used as an input value, either as an individual instance or a list of objects.
A list provided as an input value may include objects of various types.
Object data appears within the printObjects element of the internally generated print XML document (see example below), which can be processed by XPath (1.0) expressions from within the template.
The printObjects element appears in the print XML as a direct child of the root element (<core:Print>) after a set of elements reflecting properties of the current session:
The <base:User> element reflects the status of the user account (Users object identified as User of session) at the start time of the current session.
►NOTE◄ When a Guest users is logged in, a Guest users element (<base:GuestUser>) is inserted instead.The <base:CompanyAccount> reflects the status of the company account (Company accounts object idenfiied as Company of session) at the start time of the current session.
The <locale> element contains the internal key value for the Current locale as (inner) text.
The <storage> element contains all variables defined in the runtime context and their values as a list of elements with the following structure: <entry><key>...</key><value>...</value></entry>, where the <key> element defines the variable name as a String and the <value> element holds the value of the variable. An XPath expression like /core:Print/storage/entry[key="test"]/value therefore referes to the value of variable test.
►NOTE◄ Unlike the other elements the <storage> element does not appear in a print XML document, which is generated interactively via ribbon command Show print XML (see following sample). However, in that case variable do not exist anyway.
The return value of the resolver is always of the text (string) type, unless the interpretation of the template expression combines with the object data cannot be accomplished, so 'no value' (null) is returned. However, a real error that could be 'handled' with a Try/Catch actor, for example, is not triggered.
Sample content from a print XML document:
For object types featured in overviews or input forms, the export ribbon features a Show print XML command, which produces output like the following (based on the current selection).
The output presented by the neighbouring ribbon command, Show XML, largely matches the data of the same object when featured in the printObjects element of a print XML document.
The following example illustrates the structure of a print XML document base created for a single business object of the 'Shipment' type as a printObject:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
core
:Print
xmlns:base
=
"SCM.BASE"
... >
<
base
:User ...>
...
</
base
:User>
<
base
:CompanyAccount ...>
...
</
base
:CompanyAccount>
<
locale
>de</
locale
>
<
printObjects
>
<
shp
:Shipment
id
=
"305"
...>
<
attributes
>
<
shp
:ShipmentNumericValue
id
=
"63"
...>
<
value
numericValueType
=
"GROSS_WEIGHT"
value
=
"3.2"
unit
=
"kg"
/>
</
shp
:ShipmentNumericValue>
...
<
shp
:ShipmentCompanyAddress ...>
<
value
companyType
=
"CNR"
reference
=
"354234653465"
>
<
address
salutation
=
"MR"
name1
=
"John"
name2
=
"Smith"
accNumber
=
"1234567890"
accMatchCode
=
"JSmith"
street1
=
"Dusseldorf Blvd."
streetNo
=
"15"
countryCode
=
"GB"
zipcode
=
"RG6"
city
=
"Reading"
stateProvince
=
"England"
stateCode
=
"ENG"
>
<
attributes
>
<
base
:AddressCommunicationInfo
communicationType
=
"EMAIL"
communicationContext
=
"Sales"
...>
<
communicationValue
>sales@lobster.com</
communicationValue
>
</
base
:AddressCommunicationInfo>
...
</
attributes
>
</
address
>
</
value
>
</
shp
:ShipmentCompanyAddress>
...
<
shp
:ShipmentDate ...>
<
value
dateType
=
"DELIVERY_TO"
>
<
date
start
=
"1454454000000"
timeZone
=
"Europe/Berlin"
/>
</
value
>
</
shp
:ShipmentDate>
<
shp
:ShipmentDate ...>
<
value
dateType
=
"DELIVERY_FIXED"
>
<
date
start
=
"1455058800000"
end
=
"1455145199999"
timeZone
=
"Europe/Berlin"
/>
</
value
>
</
shp
:ShipmentDate>
...
</
attributes
>
<
lineItems
>
<
lineItem
numberOfPackages
=
"3"
typeOfPackaging
=
"BAG"
...>
...
</
lineItem
>
<
lineItem
numberOfPackages
=
"1"
typeOfPackaging
=
"BOX"
...>
...
</
lineItem
>
...
</
lineItems
>
</
shp
:Shipment>
</
printObjects
>
</
core
:Print>
Examples for XPath expressions retrieving content from the above print XML document:
Expression |
Return value |
Description |
Since all of the following examples share the same base path (shipment header), this part of the expression is only provided in full on the first occasion. Later examples use relative path notation with respect to the shipment header. |
||
/core:Print/printObjects/shp:Shipment |
(complete shipment) |
referred to as context ('.') in the following examples |
./@id |
305 |
The id property (id) of the shipment is an attribute (addressed with @ as prefix) in the shipment header element (<shp:Shipment>). |
./attributes/shp:ShipmentCompanyAddress/value[@companyType='CNR']/@reference |
354234653465 |
A company reference ( reference ) attribute is retrieved from the value element of a company address attribute (shp:ShipmentCompanyAddress) for Company type (companyType) 'Consignor ('CNR'). |
./attributes/shp:ShipmentDate/value[@dateType='DELIVERY_FIXED']/date/@start |
1455058800000 |
The From-value (start attribute) of the date element value (value) of a date attribute (shp:ShipmentDate) of the Date types (dateType) 'Delivery fixed'('DELIVERY_FIXED') is returned as a long value (indicating UTC milliseconds). In practice, date/time information is often formatted as a readable text value using the date() function (see below). |
./attributes/shp:ShipmentNumericValue/value[@numericValueType='GROSS_WEIGHT']/@value |
3.2 |
A plain numeric value (value attribute) is retrieved from a Numeric types (numericValueType) 'Gross weigth' ('GROSS_WEIGHT'). |
Including XPath expressions in a Template:
XPath expressions and the functions described below must be enclosed in curly brackets '{ ... }', since strings without this marking are directly output as literals.
Additionally, function names must be prefixed by a dollar sign '$' (inside the brackets).
Example: A template to generate output in HTML format:
The following shipment was delivered:<
br
>
<
br
>
<
table
>
<
tr
><
td
>ShipmentID</
td
><
td
>{/core:Print/printObjects/shp:Shipment/@id}</
td
></
tr
>
<
tr
><
td
>Delivery date fix</
td
><
td
>{$date("dd.MM.yyyy HH:mm:ss",{/core:Print/printObjects/shp:Shipment/attributes/shp:ShipmentDate/value[@dateType='DELIVERY_FIXED']/date/@start})}</
td
></
tr
>
</
table
>
<
br
>
Line items
<
br
>
<
table
>
{$foreach({/core:Print/printObjects/shp:Shipment/lineItems/lineItem})
<
tr
><
td
>Packages: {@numberOfPackages} of type:{$r("typeOfPackaging",{@typeOfPackaging})}</
td
></
tr
>
}
</
table
>
HTML output with data from a specific shipment:
HTML source code |
Representation in a browser document |
Output
The following shipment was delivered:< br > < br > < table > < tr >< td >ShipmentID</ td >< td >305</ td ></ tr > < tr >< td >Delivery date fix</ td >< td >04.02.2016 09:39:00</ td ></ tr > </ table > < br > Line items < br > < table > < tr >< td >Packages: 3 of type:Bag</ td ></ tr > < tr >< td >Packages: 1 of type:Box</ td ></ tr > </ table > |
The following shipment was delivered: ShipmentID 305 Delivery date fix 04.02 . 2016 09 : 39 : 00 Line items Packages: 3 of type:Bag Packages: 1 of type:Box |
Function available for processing data in 'Template' expressions
IMPORTANT
In the following examples, the expressions shown have been reproduced with line breaks for the sake of clearer presentation, some of which must not occur in this way within a configuration. Copying and pasting such expressions into a specific configuration is therefore not recommended, since errors or unexpected results may occur.
Function |
Syntax/Details |
Example |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
date() |
{$date(datePattern,dateValue[;Timezone])} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The datePattern uses the syntax for the java class SimpleDateFormat, as specified in detail at the following link: Pattern may be enclosed in total by double quotes (""). This enables the use of certain characters such as ( ) or , as part of the pattern, which otherwise will provoke parsing issues. Literal strings within a pattern can be 'commented out' by single quotes. This may be necessary because plain letters are either representing date components (see mapping below) or not accepted at all. Example: {$date("h'h 'mm'm'",{timestamp})} creates output like: "7h 05m" ►IMPORTANT◄ Notation rules applicable for datePatterns explained in this context, are not identical with mappings for date functions in other contexts. Since the characters and their mappings do overlap in part, it is especially important to understand and respect the specifics of mapping and rules precisely and per context when designing patterns. The following table is provided as quick reference and does not feature full details:
|
Example: Indicate value of date attribute "DELIVERY_FIXED" in default system time zone: {$date("dd.MM.yyyy HH:mm:ss (z)",{/core:Print/printObjects/shp:Shipment/attributes/shp:ShipmentDate/value[@dateType='DELIVERY_FIXED']/date/@start})} Result: "04.02.2020 09:39:00 (Europe/Berlin)" ... provided default system time zone is "Europe/Berlin" date attribute exists. ►NOTE◄ If the date attribute addressed by XPath is not found in the print XML of the shipment, the expression fails and the resolver returns 'no value' (null). Using the with() function (see following example), may help to handle this case in an elegant way. Example: Indicate value of the date attribute "DELIVERY_FIXED" in the time zone stored in the attribute: {$with(/core:Print/printObjects/shp:Shipment/attributes/shp:ShipmentDate/value[@dateType='DELIVERY_FIXED']/date){$date("dd.MM.yyyy HH:mm:ss"),{@start};{@timeZone})}
Result: "04.02.2020 07:39:00 (UTC)" ... provided the date attribute refers to time zone 'UTC'. ►NOTE◄
Example: Indicate value of date attribute "DELIVERY_FIXED" in the default time zone of User of session: {$date("dd.MM.yyyy HH:mm:ss (z)",
Result: "03.02.2020 21:39:00 (Pacific/Honolulu)" ... if the default time zone for the current user account is "Pacific/Honolulu". ►NOTE◄ If no default time zone is specified in the account of the current user, the resolver returns 'no value' overall. This case can be handled with functions if() and cmp(),, as required. A solution might look as follow: {$date("dd.MM.yyyy HH:mm:ss (z)",
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn()
|
{$fn(Number[precision=2[,integerDigits=1[,thousandsSeparator=false]]])} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This function creates a formatted String from a numerical value that must be provided or a String that can be interpreted as a numerical value. The following parameters can be optionally specified to control formatting details:
►NOTE◄ The localisations applicable to the Current locale for the language management entries lobsterui/decimalSeparator and lobsterui/thousandsSeparator are used as decimal and thousands separators. |
Example: A variable mtom in the data context contains a ‘Unit number’ (UnitNumber), which is to be output with a reference to the unit and exactly 3 decimal places. {$with({//storage/entry[key='mtom']/value}) Result: (Sample data) max. take-off mass [t]: 10,423 ►NOTE◄ The unit can only be labelled here via the ‘alias’ (see Units), which the XML structure for the UnitNumber contains directly. In contrast, the ‘name’ (name) of the associated dynamic enumeration value (e.g. TON) or the applicable localisation (e.g. ‘tonne’) is used in the string image of a UnitNumber to map the unit. In the context of the Template value resolver, there is no direct way to obtain this localisation based on the ‘Alias’ String. Example: All IDs and names of the attributes that belong to the ‘address’ (address) of the logged-in user should be listed. The IDs should be mapped as an exact six-digit integer (with ‘leading zeros’ if necessary) and thousands separators. {$foreach({/core:Print/base:User/address/attributes/*}) Result: (Sample data) #016.153 - base:AddressCommunicationInfo |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
r() Localization |
{$r(ResourceBundle,ResourceName)} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This function resolves a localization text from Localization for a given combination of Resource Bundle and Resource Name. The optional prepareValue parameter (default value: true) can be used to switch off (false) escape substitutions (e.g. for ZPL print commands). The following optional parameters (param0, param1, ...) can be used to provide values for the corresponding placeholders ({0}, {1}, ...) in localization texts. ►NOTE◄ Unlike other Localization access methods, the r() function does not provide a definition for a default value that would be assigned as a return value if no entry exists for the given combination of Resource Bundle and Resource Name. |
Example: Apply a label for a date value according to the localization for the given Date types {$with ({/core:Print/printObjects/shp:Shipment/attributes/shp:ShipmentDate/value[@dateType='DISPATCH_DATE']}) {$r(de.lobster.scm.base.bto.attribute.DateType,{@dateType})}: {$date(y-MM-dd,{date/@start})}} Result: "Dispatch date: 2020-02-19"
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with() XPath context |
{$with({XPathExpression})TemplateExpression} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The with() function resolves an XPathExpression to define a specific element in the print XML as a point of reference for the interpretation of any relative path found within the TempalteExpression of the with() function. Effectively, a 'base path' common to several XPath expressions will only be featured once within the bracketed header clause '( )', making the TemplateExpression shorter and more transparent. Besides, the use of relative paths in the TemplateExpression will improve the chances of being able to cut & paste content to a different context without adaptations. Relative paths in XPath expressions may refer to parent levels 'above' the original level provided by the with() function (e.g. by '../'). Besides, it is always possible to refer to any other element within the print XML from within a TemplateExpression using absolute paths. The TemplateExpression may contain more or less complex expressions, to include further calls of the with() function, which temporarily define a new 'nested' context. ►NOTE◄ If the XPathExpression returns more than one element, only the first 'match' will be used as a context for processing the TemplateExpression. To loop over all nodes returned by an XPath expression, refer to the foreach() function (see below), instead of with(). |
Example: Structured output of address data from a company account {$with ({/core:Print/printObjects/base:CompanyAccount/address}) #{ @accNumber } (ID {../ @id }) { @name1 } { @name2 } { @name3 } { @street1 } { @streetNo } { @zipcode } { @city } {$r(de.lobster.scm.localization.Country,{ @countryCode })} }
Result: Presentation of the string returned by the resolver in a pop-up of the 'Info' type: Example: Similar presentation of addess data from the company attributes (Company type AAL and CNE) of an order: {$with ({/core:Print/printObjects/ord:Order/attributes/ord:OrderCompanyAddress/value[ @companyType = 'AAL' ]/company/address}) {$r(de.lobster.scm.base.company.CompanyType,{../../ @companyType })} ------------------------------------- #{ @accNumber } (ID {../ @id }) { @name1 } { @name2 } { @name3 } { @street1 } { @streetNo } { @zipcode } { @city } {$r(de.lobster.scm.localization.Country,{ @countryCode })} } {$with ({/core:Print/printObjects/ord:Order/attributes/ord:OrderCompanyAddress/value[ @companyType = 'CNE' ]/company/address}) {$r(de.lobster.scm.base.company.CompanyType,{../../ @companyType })} ------------------------------------- #{ @accNumber } (ID {../ @id }) { @name1 } { @name2 } { @name3 } { @street1 } { @streetNo } { @zipcode } { @city } {$r(de.lobster.scm.localization.Country,{ @countryCode })} }
Result:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach() Loop over XPath elements |
{$foreach({XPathExpression}) TemplateExpression} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The TemplateExpression is interpreted in a loop over all elements (if any) returned by XPathExpression. Each iteration of this loop uses another instance from a list of nodes returned by XPathExpression as a context for interpreting any relative XPath expressions found in the TemplateExpression. The TemplateExpression may contain more or less complex expressions, to include further calls of the foreach() function, which temporarily define a new 'nested' context and set of elements to iterate (see the final example on the right). |
Example: Following the outlines of the examples for the with() function (see above), the given address section layout should be used to create a list featuring all companies involved. {$foreach ({/core:Print/printObjects/ord:Order/attributes/ord:OrderCompanyAddress/value/company/address}) {$r(de.lobster.scm.base.company.CompanyType,{../../ @companyType })} ------------------------------------- #{ @accNumber } (ID {../ @id }) { @name1 } { @name2 } { @name3 } { @street1 } { @streetNo } { @zipcode } { @city } {$r(de.lobster.scm.localization.Country,{ @countryCode })} } Result: A list of company addresses, as in the previous example, but listing addresses for more company types (if any). Example: Creating HTML content to define the involvement of the current company with an order by a list of Company type. < table >{$foreach ({/core:Print/printObjects/ord:Order/attributes/ ord:OrderCompanyAddress/value[company/@id=/core:Print/base:CompanyAccount/@id]}) < tr > < td >{@companyType}</ td > < td >{$r(de.lobster.scm.base.company.CompanyType,{@companyType})}</ td > </ tr >} </ table >
Result: (based on an different order from the one used in the examples for the with() function).
Example: As an abstract from the data of an order an HTML list of all addressed contained should be generated, featuring selected address properties as list items (as far as provided). {$with({/core:Print/printObjects}) {$foreach({.//address|.//contactAddress}) < p >ADDRESS # {@id} < ul >{$foreach({@*[starts-with(name(),'name') or starts-with(name(),'street') or contains('|zipcode|city|countryCode|',concat('|',name(),'|'))]}) < li >{.}</ li >} </ ul ></ p >} }
Result: (clipped from a larger list)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if() Condition |
{$if(ifExpression) {then thenExpression} [{elseif (elseifExpression) elseifthenExpression}] [{else elseExpression}]}OR alternative simplified syntax: {$if(ifExpression)thenExpression} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The value returned by the ifExpression influences, which of the other expressions included in a function call are evaluated to determine the return value of the if() function. The sole criterion is whether the value returned by an ifExpression matches the string 'true' (non-case sensitive). If that is the case, the 'if' condition is satisfied. Occasionally, data from the print XML may data immediately meet that requirement, for instance, data of the 'Boolean' type as demonstrated in the first example to the right. However, in most cases an ifExpression requires the definition of a more or less complex cirterion, to 'digitize' or translate data of other data types into Boolean values using the cmp() function. If required, several Boolean intermediate results can be processed into larger aggregates by logical operators $and(), $or and $not() within an ifExpression. Procedure to evaluate the return value per case (then – elseif – else): If the condition specified by ifExpression is satisfied, the parameters of the function call are searched for an expression introduced by the keyword then. If this exists, the contained thenExpression is evaluated to determine the return value of the if() function. If the keyword then is not found at all, the resolver is aborted returning 'no value' – unless the simplefied syntax (see above) is used, where the thenExpression follows the ifExpression immediately and without using a keyword (see the second example on the right). If the condition specified by ifExpression is not satisfied, the parameters of the function call search for an expression introduced by the keyword elseif. Any expressions introduced by that keyword will be processed in the order of their appearance, by evaluating whether the return value of the contained elseifExpression matches the string 'true'. In that case, the respective 'elseif' condition files as satisfied and the corresponding elseifthenExpression is evaluated to determine the return value of the if() function. If the 'elseif' condition is not satisfied, the evaluation is continued with the next elseifExpression in line (if any). If all 'elseif' conditions in expressions introduced by elseif are not satisfied, or no such expressions exist, an expression with the keyword else is searched in the function call parameters. If that exists, the contained elseExpression is evaluated to determine the return value of the if() function. Otherwise, the return value is defaulted to an empty string. ►NOTE◄ It is technically possible to define expressions with the keywords then and else more than once in the same function call. However, the evaluation procedure described above will – in contrast to elseif – only evaluate the first instance per type. ►IMPORTANT◄ Logical functions inside an ifExpression must be enclosed by curly brackets to ensure a Boolean value is 'resolved' as an intermediate result: {$if({$or(true,false)})CORRECT} returns 'CORRECT', in contrast to an expression like |
Example: Name and value tuples for all flag attributes (see Flag type) found in an arbitrary context should be featured in a list, in which flag values should be symbolized by the characters 'X' (true) and 'O' (false). {$foreach({.//value[@flagValue and @flagType]})
Result: Sample output in a popup listing flag settings for a user account, where three flags exist out of which one is 'checked' (value 'true') and two are not set (but explicitly feature 'false' as a value):
Example: In addition to the solution in the previous example, the output string should feature a special status text (e.g. 'Contacting prohibited!'), if none of the flags representing consent for a type of contact is set for a user account: {$if({$not({$or( {.//value[@flagType='SEND_MAIL']/@flagValue},
►NOTE◄ If a flag attribute (or the contained flagValue field) is not found, when the ifExpression is interpreted, the respective argument of the or() function makes an empty string ('') against 'true', which files as 'false'. Whether the flag was not found or explicitly set to 'false', does not make a difference for further evaluations. Since flags in the given context express consent for being contacted in a certain way, the resulting 'opt-in' logic might match user requirements perfectly. To interpret the same flags for 'opt-out' logic instead, the ifExpression would have to be rearranged as follows: {$if({$and( {$cmp({.//value[@flagType='SEND_MAIL']/@flagValue},=,false)}, {$cmp({.//value[@flagType='SEND_NEWS']/@flagValue},=,false)})}){$r{PRIVACY_STATUS,ZERO_SPAM}}}
►NOTE◄ Since the simplified syntax of the if() function ultimately only causes a 'conditional output' of the then expression, a comparable result can often also be achieved by formulating a comparable logic in the predicate of an XPath expression within a with() function. For an 'opt-out' check in the example, the following approach would also be useful: {$with({./attributes[ .//value[@flagType='SEND_MAIL' and @flagValue='false'] and .//value[@flagType='SEND_NEWS' and @flagValue='false'] ]}){$r{PRIVACY_STATUS,ZERO_SPAM}}} The attributes element defining the with() context here is part of the not completely reproduced context of the original expression. The predicate to this element verify, when both flags exist and explicitly return 'false' as a flag value (flagValue). Example: A text for a message should appear on a personalized basis on the address properties ('Salutation' and 'Last name'). We assume the last name will always be stored in the 'Name 3' (name3) property of an address and only 'MR' and 'MS' (see Salutation) are the only relevant selections for 'Salutation' in the given context. {$with({/core:Print/base:User/address}) Hello {$ if ({$cmp({ @salutation },=,MR)}){then Mr.} {elseif ({$cmp({ @salutation },=,MS)})Mrs.} { else User}} { @name3 }! ... }
►NOTE◄ A blank character following one of the keywords then, else or elseif is considered part of the syntax and not part of the following literal. However, the syntax does not require a blank character after the closing bracket after the elseifExpressionliteral. For this reason {then Mr.} and {else User} are correct, where {elseif (...) Mrs.} would add a redundant blank character to the output string before 'Mrs.'. Results:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cmp() Comparison |
{$cmp(leftExpression,relationalOperator,rightExpression[,compareDataType])} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The cmp() function compares return values or literals provided as leftExpression and rightExpression using a specified relationarOperator, and returns 'true' as a string if the condition defined by these parameters is passed (or else: 'false').
The optional comparison data type parameter defines a specific target data type for interpreting the return values of leftExpression and rightExpression when checking the comparison condition.
►NOTE◄ Unless specified otherwise expressions are compared as strings, which will only yield the expected results under special circumstances when numerical values are compared without an indication of the applicable compareDataType. Basically, an indication of compareDataType is always resommended for comparing numbers, even if an expression without an explicit choice of data type seems to produce plausible results in sample testing. If a numerical compareDataType is selected, the return values of leftExpression and rightExpression must be acceptable input for the target format, or else the resolver will either FAIL (abort returning 'no value') or the compare result may be unreliable. In practice the following requirements should be observed (also see the examples on the right):
Date/time values, typically provided in mumerical form (UTC milliseconds), can be handled as numbers by double comparison or by strings comparison, provided the milliseconds are converted to a suitable format using the date() function. Clever choices for the date pattern for a string copmarison will enable much more specific criteria than just checking the relative position of two timestamps on a UTC time line (see examples to the right). Boolean values, e. g. from flag attributes, can be handled by string comparison with values 'true' and 'false'. ►NOTE◄ If string values from expressions are referred to as 'booleans' in string comparisons, the common use of lower case may not always be granted. In case of doubt it is recommended to run text input with potentially variable case through an and() or or() function to force it to lower case. Example: A comparison should determine whether two hypothetical properties (required and granted) of a certain element (permission) bear the same Boolean value. The relevant section of a print XML might look like this: <permission type= "00" required= "TRUE" granted= "true" ></permission> An expression like {$cmp(@required,=,@granted)} would return 'false' for this element, because the strings are not identical. Clearly this interpretation in not beneficial for the task of comparing Booleans. The following expression ensures a not case-sensitive evaluation and returns 'true' with the sample data above: {$cmp({$or({@required})},=,{$or({@granted})})} |
Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and() Logical conjunction |
{$and([Expression[,Expression[,...]]])} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The and() function defines a logical conjunction (AND-junction) between the values of all Expression arguments, i.e. if all Expressions return a value matching the string 'true' (not case-sensitive), and() returns 'true' and in any other case 'false'. |
Example: Xpath expressions and functions may replace any of the literal arguments used in these examples for better transparency.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
or() Logical disjunction |
{$or([Expression[,Expression[,...]]])} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The or() function defines a logical disjunction (OR-junction) between the values of all Expression arguments, i.e. if only one Expression returns a value matching the string 'true' (not case-sensitive), or() returns 'true' , otherwise: 'false'. |
Example: Xpath expressions and functions may replace any of the literal arguments used in these examples for better transparency.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
not() Logical negation |
{$not(Expression)} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The not() function negates a Boolean value returned from the Expression. If this values matches the string 'true' (not case-sensitive), not() returns 'true' , otherwise: 'false'. |
Example: Xpath expressions and functions may replace any of the literal arguments used in these examples for better transparency.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
substr() Substring |
{$substr(startIndex,maxLength,Expression)} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The substr() function extracts a defined section of the string returned by Expression. The other arguments define the position of the first character to return and the (maximum) length of the returned substring. These argument values cannot be defined by expressions, but require static numbers (of data type integer):
►NOTE◄ Internally an 'endindex' calculation adds startIndex + maxLength, so this value must fit the number range for integer values (max. 231-1 = 2147483647). |
Example: The following examples are designed for the context of an address element matching the following print XML excerpt: ... <address id=... name1= "♥ Karola" name2= "" name3= "Mustermann" > ... </address> ... We assume the following expressions are executed in a with() context returning this address element:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bsh() bsh script |
{$bsh(scriptExpression)} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The scriptExpression is executed as bsh script and the interpreted value is returned as a string. |
|