Path expressions
Path expressions give ModelDesk a compact way to navigate between the elements of a model. They provide a concise, readable syntax for traversing relationships, filtering elements, and expressing complex navigation patterns.
Most users never write a path expression. ModelDesk uses them internally throughout its configuration (the shipped mappings that power transformations, the diagram definitions that decide which related elements a diagram pulls in, and metamodel property definitions), and there you only see their results, never the expressions. You read or write one yourself in two situations:
- Feature-specific builders. A few capabilities that ModelDesk can enable for your organization include an expression builder in which you compose a path expression, or read the generated one, to select elements.
- Working on ModelDesk configuration. If you author or review mappings or metamodel configuration together with ModelDesk, this page is the reference for the expressions in those files.
If neither applies to you, you can skip this page.
This page is the syntax reference. The example expressions use relation and type names (such as modelelement,
attribuut, and Objecttype) drawn from real metamodels; the names available to you depend on the standard your
model uses.
Basic syntax
Section titled “Basic syntax”Path expressions can be written as strings in YAML mappings:
path: "modelelement[@type='Objecttype']"Or as structured YAML objects for more complex cases:
path: relation: modelelement filter: '@type': ObjecttypeOr as JSON objects:
{ "path": { "relation": "modelelement", "filter": { "@type": "Objecttype" } }}The string format is preferred for readability when the path can be expressed concisely.
Navigation
Section titled “Navigation”Current element
Section titled “Current element”Use . to refer to the current element:
path: '.'This is useful when you want to apply a filter to the current element:
path: ".[@type='Package']"Owner (parent)
Section titled “Owner (parent)”Use @owner to navigate to the parent (owner) element:
path: '@owner'Navigate to the grandparent:
path: '@owner/@owner'Walk it the other way with ^ to reach the elements the current element owns, in every relation that owns them:
path: '^@owner'Relations
Section titled “Relations”Navigate a relation by its name:
path: 'modelelement'Chain multiple relations:
path: 'modelelement/attribuut'@-prefixed relations
Section titled “@-prefixed relations”Some metamodels use @-prefixed relation names like @element, @dependency, or @namespace. These are supported
directly:
path: "@owner/@element[@type='Extern']"Inverse relations
Section titled “Inverse relations”Use ^ to navigate a relation in the inverse direction (from target back to source):
path: '^modelelement'This finds all elements that have a modelelement relation pointing to the current element.
Inverse with grouping
Section titled “Inverse with grouping”Apply inverse to grouped expressions:
# Inverse of an alternativepath: '^(attribuut|data-element|relatiesoort)'
# Inverse of a sequencepath: '^(modelelement/attribuut)'Double inverse
Section titled “Double inverse”Double inverse returns to the original direction:
path: '^^relation' # Equivalent to "relation"Path composition
Section titled “Path composition”Sequences
Section titled “Sequences”Use / to chain path segments sequentially:
path: 'modelelement/attribuut/type'Each segment is evaluated in order, with the result of one segment becoming the input for the next.
Alternatives
Section titled “Alternatives”Use | to specify alternative paths:
path: 'attribuut|relatiesoort|gegevensgroep'This matches elements reachable via any of the specified relations.
Grouping
Section titled “Grouping”Use parentheses to group expressions:
path: '(attribuut|relatiesoort)/type'This navigates via either attribuut or relatiesoort, then follows type from the result.
Grouping is required when applying quantifiers or filters to compound expressions:
path: '(modelelement/attribuut)*'Quantifiers
Section titled “Quantifiers”Quantifiers specify how many times a path segment can be traversed:
| Quantifier | Meaning | Description |
|---|---|---|
| (none) | Exactly one | Default: traverse exactly once |
? |
Zero or one | Optional traversal |
* |
Zero or more | Traverse any number of times (including zero) |
+ |
One or more | Traverse at least once |
Examples
Section titled “Examples”Optional relation:
path: 'type?'Recursive traversal (zero or more):
path: 'subpackage*'At least one level:
path: 'subpackage+'Combined with other segments:
path: "package*/modelelement[@type='Objecttype']"Filters
Section titled “Filters”Filters narrow down which elements match a path segment. They are enclosed in square brackets [...].
Type filters
Section titled “Type filters”Filter by element type:
# Exact type matchpath: "modelelement[@type='Objecttype']"
# Multiple types (OR)path: "modelelement[@type in ('Objecttype', 'Gegevensgroeptype')]"Attribute filters
Section titled “Attribute filters”Filter by attribute value:
# Exact matchpath: "modelelement[naam='Persoon']"
# Multiple values (OR)path: "modelelement[naam in ('Persoon', 'Adres')]"Comparison operators
Section titled “Comparison operators”| Operator | Meaning |
|---|---|
= |
Equals |
!= |
Not equals |
< |
Less than |
> |
Greater than |
<= |
Less than or equal |
>= |
Greater than or equal |
path: 'attribuut[minKardinaliteit >= 1]'ID filters
Section titled “ID filters”Filter by element ID:
path: "modelelement[@id='abc123']"Root filter
Section titled “Root filter”Match only root elements:
path: '.[@root]'Presence filters
Section titled “Presence filters”@present
Section titled “@present”Match elements where a path exists (has results):
path: 'modelelement[@present(type)]'This matches modelelement entries that have a type relation.
@absent
Section titled “@absent”Match elements where a path does not exist:
path: 'modelelement[@absent(deprecated)]'This matches modelelement entries that do not have a deprecated relation.
Generic filters
Section titled “Generic filters”For advanced filtering, use the generic filter syntax:
@category:filterType(arguments)Type category
Section titled “Type category”path: "modelelement[@type:equals('Objecttype')]"path: "modelelement[@type:in('Objecttype', 'Keuze')]"Attribute category
Section titled “Attribute category”# Check if attribute is emptypath: "modelelement[@attr:isEmpty(attribute: 'definitie')]"
# Check attribute equals valuepath: "modelelement[@attr:equals(attribute: 'naam', value: 'Persoon')]"Named arguments use the format name: value:
path: ".[@attr:isEmpty(attribute: 'xsdTargetNamespace')]"ID category
Section titled “ID category”path: "modelelement[@id:equals('abc123')]"Logical operators
Section titled “Logical operators”Combine predicates with logical operators:
path: "modelelement[@type='Objecttype' and naam='Persoon']"path: "modelelement[@type='Objecttype' or @type='Keuze']"path: "modelelement[not @type='Abstract']"path: "modelelement[not @attr:isEmpty(attribute: 'definitie')]"Complex combinations
Section titled “Complex combinations”path: "modelelement[@type='Objecttype' and (naam='Persoon' or naam='Adres')]"Indexes
Section titled “Indexes”Use [n] after a relation or grouped expression to select a single element at a specific position in a multi-valued
result. The index is zero-based.
Basic index access
Section titled “Basic index access”Select the first element of a relation:
path: 'ownedEnd[0]'Select the second element:
path: 'ownedEnd[1]'If the index is out of bounds (for example, [5] on a relation with only 2 targets), the result is empty.
Index in sequences
Section titled “Index in sequences”Indexes can be used on individual segments within a sequence. This is useful when navigating through ordered relations:
# Get the type of the first owned endpath: 'ownedEnd[0]/type'
# Get the type of the second owned endpath: 'ownedEnd[1]/type'Index with other modifiers
Section titled “Index with other modifiers”Indexes can be combined with inverse navigation, quantifiers, and grouped expressions:
# Index on an inverse relationpath: '^children[0]'
# Index on a quantified relationpath: 'children*[0]'
# Index on a grouped alternativepath: '(attribuut|relatiesoort)[0]'Modifiers
Section titled “Modifiers”Greedy modifier
Section titled “Greedy modifier”A quantified step normally stops as soon as a repetition depth yields matches. Use ! after the quantifier to
make it greedy: it then collects the matches of every depth. The difference for subpackage*, starting from a
package that itself qualifies:
path: 'subpackage*' # the starting package only (zero steps already match)path: 'subpackage*!' # the starting package plus its subpackages at every depthDistinct modifier
Section titled “Distinct modifier”Use # at the end of a path expression to remove duplicates:
path: '(attribuut | relatiesoort | gegevensgroep)#'This ensures each element appears only once in the result, even if reachable via multiple paths. The distinct modifier can be applied to any path expression:
# On alternativespath: '(attribuut | relatiesoort)#'
# On sequencespath: 'nestedPackage*/packagedElement#'
# On single relationspath: 'type#'Path combiners
Section titled “Path combiners”Path combiners evaluate multiple paths and produce a single derived value. They appear in ModelDesk configuration
(metamodel and mapping files) as the value of a const field on a property, computing an attribute value from the
results of two or more path expressions.
Combiner syntax
Section titled “Combiner syntax”Combiners use a function-call shorthand with @ prefix:
@combinerName(path1, path2, ...)Each argument is a path expression. The combiner evaluates all paths against the current element and combines the results according to its logic.
For example:
{ "const": "@equals(onderwerp, ^gegevenstype/hoofdonderwerp)"}Or equivalently in the expanded form:
const: path: - onderwerp - '^gegevenstype/hoofdonderwerp' combine: equals@equals combiner
Section titled “@equals combiner”The @equals combiner compares the results of two or more paths and returns true if all results are equal, or
false if they differ.
@equals(path1, path2)Behavior:
| Path 1 result | Path 2 result | Output |
|---|---|---|
"foo" |
"foo" |
true |
"foo" |
"bar" |
false |
["a", "b"] |
["a", "b"] |
true |
| empty | "foo" |
null |
| empty | empty | null |
When any path resolves to an empty result, @equals returns null (undefined) rather than comparing empty values.
This leniency prevents false positives when an element simply lacks the data needed for comparison.
Example: compute whether a data type is “direct” by comparing two navigation paths:
{ "const": "@equals(onderwerp, ^gegevenstype/hoofdonderwerp)"}This evaluates both onderwerp and ^gegevenstype/hoofdonderwerp from the current element. If both resolve to the
same element, the result is true. If either path has no result, the value is left undefined.
@and combiner
Section titled “@and combiner”The @and combiner checks whether all paths resolve to non-empty results. It returns true only if every path
produces at least one element.
@and(path1, path2, ...)Behavior:
| Path 1 result | Path 2 result | Output |
|---|---|---|
| present | present | true |
| present | empty | false |
| empty | present | false |
| empty | empty | false |
The combiner requires at least two path arguments. If fewer than two paths are provided, it returns false.
Example: compute whether an element is “unique” by checking that it has both a main subject and a key-part data type:
{ "const": "@and(hoofdonderwerp, gegevenstype[sleutelonderdeel = true])"}This returns true only if the current element has a non-empty hoofdonderwerp relation and has at least one
gegevenstype relation whose target has sleutelonderdeel = true. Path arguments can use the full path expression
syntax including filters, sequences, and inverse navigation.
Complete examples
Section titled “Complete examples”Navigate to all objecttypes in nested packages
Section titled “Navigate to all objecttypes in nested packages”path: "package*/modelelement[@type='Objecttype']"Find elements with non-empty definitions
Section titled “Find elements with non-empty definitions”path: "modelelement[not @attr:isEmpty(attribute: 'definitie')]"Navigate to external schema dependencies
Section titled “Navigate to external schema dependencies”path: "@owner/@element[@type='Extern' and not @attr:isEmpty(attribute: 'xsdTargetNamespace')]"Find all attributes and relations with types
Section titled “Find all attributes and relations with types”path: '(attribuut|relatiesoort)[@present(type)]'Inverse navigation with type filter
Section titled “Inverse navigation with type filter”path: "^(attribuut|data-element|relatiesoort)/^modelelement[@type='Package']"Root element with specific type
Section titled “Root element with specific type”path: ".[@root and @type='Informatiemodel']"Complex mapping path
Section titled “Complex mapping path”path: "modelelement[@type='Package' and @present(xsdTargetNamespace) and not naam in ('internal-pkg', 'excluded')]"Navigate to the first owned end’s type
Section titled “Navigate to the first owned end’s type”path: 'ownedEnd[0]/type'Computed boolean with path combiner
Section titled “Computed boolean with path combiner”{ "const": "@and(hoofdonderwerp, gegevenstype[sleutelonderdeel = true])"}Quick reference
Section titled “Quick reference”Navigation
Section titled “Navigation”| Syntax | Description |
|---|---|
. |
Current element |
@owner |
Parent (owner) element |
relationName |
Follow relation |
@relationName |
Follow @-prefixed relation |
relation[n] |
Relation with index |
^relation |
Inverse relation |
^(expr) |
Inverse of grouped expression |
Composition
Section titled “Composition”| Syntax | Description |
|---|---|
a/b |
Sequence (a then b) |
a|b |
Alternative (a or b) |
(...) |
Grouping |
Quantifiers
Section titled “Quantifiers”| Syntax | Description |
|---|---|
| (none) | Exactly one |
? |
Zero or one |
* |
Zero or more |
+ |
One or more |
Indexes
Section titled “Indexes”| Syntax | Description |
|---|---|
[n] |
Index (zero-based) |
Modifiers
Section titled “Modifiers”| Syntax | Description |
|---|---|
! |
Greedy modifier |
# |
Distinct modifier |
Filters
Section titled “Filters”| Syntax | Description |
|---|---|
[@type='X'] |
Type equals |
[@type in ('X', 'Y')] |
Type in list |
[attr='value'] |
Attribute equals |
[attr in ('a', 'b')] |
Attribute in list |
[@id='X'] |
ID equals |
[@root] |
Is root element |
[@present(path)] |
Path exists |
[@absent(path)] |
Path does not exist |
[@category:type(args)] |
Generic filter |
Logical operators
Section titled “Logical operators”| Syntax | Description |
|---|---|
and |
Logical AND |
or |
Logical OR |
not |
Logical NOT |
(...) |
Grouping |
Comparison operators
Section titled “Comparison operators”| Syntax | Description |
|---|---|
= |
Equals |
!= |
Not equals |
< |
Less than |
> |
Greater than |
<= |
Less than or equal |
>= |
Greater than or equal |
Literals
Section titled “Literals”| Type | Example |
|---|---|
| String | 'value' |
| Number | 42, -3.14 |
| Boolean | true, false |
| Null | null |
Path combiners
Section titled “Path combiners”| Syntax | Description |
|---|---|
@equals(p1, p2) |
true if all paths resolve to equal values; null if any path is empty |
@and(p1, p2, ...) |
true if all paths resolve to non-empty results |