Skip to content

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.

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': Objecttype

Or as JSON objects:

{
"path": {
"relation": "modelelement",
"filter": {
"@type": "Objecttype"
}
}
}

The string format is preferred for readability when the path can be expressed concisely.

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']"

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'

Navigate a relation by its name:

path: 'modelelement'

Chain multiple relations:

path: 'modelelement/attribuut'

Some metamodels use @-prefixed relation names like @element, @dependency, or @namespace. These are supported directly:

path: "@owner/@element[@type='Extern']"

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.

Apply inverse to grouped expressions:

# Inverse of an alternative
path: '^(attribuut|data-element|relatiesoort)'
# Inverse of a sequence
path: '^(modelelement/attribuut)'

Double inverse returns to the original direction:

path: '^^relation' # Equivalent to "relation"

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.

Use | to specify alternative paths:

path: 'attribuut|relatiesoort|gegevensgroep'

This matches elements reachable via any of the specified relations.

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 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

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 narrow down which elements match a path segment. They are enclosed in square brackets [...].

Filter by element type:

# Exact type match
path: "modelelement[@type='Objecttype']"
# Multiple types (OR)
path: "modelelement[@type in ('Objecttype', 'Gegevensgroeptype')]"

Filter by attribute value:

# Exact match
path: "modelelement[naam='Persoon']"
# Multiple values (OR)
path: "modelelement[naam in ('Persoon', 'Adres')]"
Operator Meaning
= Equals
!= Not equals
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
path: 'attribuut[minKardinaliteit >= 1]'

Filter by element ID:

path: "modelelement[@id='abc123']"

Match only root elements:

path: '.[@root]'

Match elements where a path exists (has results):

path: 'modelelement[@present(type)]'

This matches modelelement entries that have a type relation.

Match elements where a path does not exist:

path: 'modelelement[@absent(deprecated)]'

This matches modelelement entries that do not have a deprecated relation.

For advanced filtering, use the generic filter syntax:

@category:filterType(arguments)
path: "modelelement[@type:equals('Objecttype')]"
path: "modelelement[@type:in('Objecttype', 'Keuze')]"
# Check if attribute is empty
path: "modelelement[@attr:isEmpty(attribute: 'definitie')]"
# Check attribute equals value
path: "modelelement[@attr:equals(attribute: 'naam', value: 'Persoon')]"

Named arguments use the format name: value:

path: ".[@attr:isEmpty(attribute: 'xsdTargetNamespace')]"
path: "modelelement[@id:equals('abc123')]"

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')]"
path: "modelelement[@type='Objecttype' and (naam='Persoon' or naam='Adres')]"

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.

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.

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 end
path: 'ownedEnd[0]/type'
# Get the type of the second owned end
path: 'ownedEnd[1]/type'

Indexes can be combined with inverse navigation, quantifiers, and grouped expressions:

# Index on an inverse relation
path: '^children[0]'
# Index on a quantified relation
path: 'children*[0]'
# Index on a grouped alternative
path: '(attribuut|relatiesoort)[0]'

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 depth

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 alternatives
path: '(attribuut | relatiesoort)#'
# On sequences
path: 'nestedPackage*/packagedElement#'
# On single relations
path: 'type#'

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.

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

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.

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.

Section titled “Navigate to all objecttypes in nested packages”
path: "package*/modelelement[@type='Objecttype']"
path: "modelelement[not @attr:isEmpty(attribute: 'definitie')]"
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)]'
path: "^(attribuut|data-element|relatiesoort)/^modelelement[@type='Package']"
path: ".[@root and @type='Informatiemodel']"
path: "modelelement[@type='Package' and @present(xsdTargetNamespace) and not naam in ('internal-pkg', 'excluded')]"
path: 'ownedEnd[0]/type'
{
"const": "@and(hoofdonderwerp, gegevenstype[sleutelonderdeel = true])"
}
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
Syntax Description
a/b Sequence (a then b)
a|b Alternative (a or b)
(...) Grouping
Syntax Description
(none) Exactly one
? Zero or one
* Zero or more
+ One or more
Syntax Description
[n] Index (zero-based)
Syntax Description
! Greedy modifier
# Distinct modifier
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
Syntax Description
and Logical AND
or Logical OR
not Logical NOT
(...) Grouping
Syntax Description
= Equals
!= Not equals
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
Type Example
String 'value'
Number 42, -3.14
Boolean true, false
Null null
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