XPath System Variable syntax

I noticed that XPath syntax is slightly different when it’s used as an XPath constraint in a data widget (like List) compared to when it’s used as a visibility condition:   As a datasource XPath constraint: [StartDateAndTime >= '[%BeginOfCurrentDay%]']   As visibility condition expression however: $Match/StartDateAndTime < [%BeginOfCurrentDay%]   Could someone explain (and maybe include a link to the relevant doc) why we have two different forms for the system variable [%BeginOfCurrentDay%] in the above examples? – Thanks.
1 answers

Hi Johny,


You are correct that the syntax for system variables like [%BeginOfCurrentDay%] can be different when used in XPath constraints for data widgets (e.g., data source constraint for a List) compared to visibility condition expressions. This is due to the context in which these expressions are evaluated.

1. Data Source XPath Constraint:
   - When used as a data source XPath constraint, the expression is evaluated within the context of the entity that the data widget is displaying. In this context, the system variables need to be enclosed in single quotes (' ') to be treated as string literals. The single quotes indicate that the value is a string representation of the date or time.


[StartDateAndTime >= '[%BeginOfCurrentDay%]']

2. Visibility Condition Expression:
   - On the other hand, when used as a visibility condition expression, the system variables are evaluated as expressions directly and do not need to be enclosed in single quotes. The system variable will be replaced with its actual value before evaluating the visibility condition.


$Match/StartDateAndTime < [%BeginOfCurrentDay%]


As for the relevant documentation, you can find information about using expressions in Mendix in the official Mendix documentation under the section "Expressions in Mendix":
Expressions in Mendix - Mendix Documentation

This documentation explains how expressions are used in various contexts, including data source constraints and visibility conditions, and provides examples of using system variables like [%BeginOfCurrentDay%].


In XPath constraints for data widgets, system variables are treated as string literals and need to be enclosed in single quotes, while in visibility conditions, system variables are evaluated as expressions without the need for single quotes.