1. Home
  2. Docs
  3. Chapter 23. Document Production
  4. 5. Writing Doc. Composer element templates
  5. Sorting in Loop

Sorting in Loop

Download PDF

Add <Sortings> under a loop element (e.g. <IterationBlock>, <ForEach>) to sort retrieved elements. <Sortings> contains one or more <Sorting>. Each <Sorting> defines a way to sort the elements retrieved. The following example show the use of <Sorting> in a template.

<IterationBlock modelType="class">
        <Sorting by="property" property="name"/>
    <Property property="name"/>

Here is the outcome of the example above.


The following table lists the available attributes of <Sorting>.

Name Description/Usage Required?
by : string

{name | type | modelType | diagramType | property | followTree | level | businessProcessFlow}

Sort by any of the following options:

– name : sort by name
– type : sort by type (type of model element or diagram)
– modelType : sort by model element’s type
– diagramType : sort by diagram type
– property: sort by property, requires the definition of @property, @sortValues, @defaultPropertyValue
– followTree: sort following how elements are being sorted in Model Navigator and Diagram Navigator
– level: sort by parent-child
– businessProcessFlow:
sorting the BPD elements by the ordering in BPD (calculated by their ordering in sequence/message flow).
ONLY AVIALABLE for sorting Diagram Elements in a BPD

property : string If @by=”property”, you have to specify @property to specify the property to be sorted.

You can also sort elements by their tagged values by specifying this:
Replace TAG_NAME with the name of the tag to be sorted

sortValues : string If @by=”property”, you can specify @sortValues to define the ordering of values to be sorted.

@by=”property” @property=”visibility” @sortValues=”public, protected, private”
means ‘public’ model elements will list before ‘protected’ model elements, ‘protected’ will list before ‘private’

defaultPropertyValue : string If  @by=”property”, @defaultPropertyValue can be specified for the default value of the model elements that don’t have this property value. Optional
descending : boolean Sorting in descending order. Optional
dateFormatString : string Date value property will be formatted with the format pattern specified before sorting. Formatting will only occur when the property is a date value (e.g. pmLastModified).

e.g. @dateFormatString =”yyyy-MM-dd”


Suppress the default way of sorting

Without using <Sortings> and <Sorting>, elements in loop will still be sorted alphabetically. If you want to suppress the default way of sorting, write <Sortings noSort=”true”/>. Here is an example:

<IterationBlock modelType="class">
<Sortings noSort="true"/>
<Property property="name"/>