repeat over current elements
Full Description
swirl
Syntax
  repeat over reversed? current elements element-qualifier*
     as alias-name
   local-declaration*
   action*
  again


Purpose

A form of the repeat over action used to "iterate over" opened elements and access information about them. The default behavior of a repeat over current elements loop is to start with the element that was opened first and iterates "forward" to the most recently opened element, processing each open element in turn.

Within a repeat over current elements action, the alias-name provides a way to access the current element selected in the iteration. An element definition alone always identifies the currently opened element, and not the current item of the iteration. The element selected by the current iteration is always identified by the current element element alias name in the head of the repeat over action. This also works for several elements at once, because a single repeat over can be applied to both current elements and reversed current elements simultaneously. repeat over current elements must define an "alias" for the opened element selected in each iteration. The form current-element followed by the alias name is used to identify any reference to the selected element.

The repeat over reversed current elements action iterates over the most recently opened element and iterates "backwards" over the remainder of the currently opened elements, from the most recently opened element to the "oldest" open element (that is the one that was opened first).

If there are no open elements, or the qualifier following repeat over current elements of identifies an open element that does not exist, the repeat over action is not executed: it effectively identifies an empty set of opened elements.

#item is always one (1) on the first iteration, and the number of opened items on the last iteration, even when the reversed option is used. #item never decrements.

The current elements "shelf" differs from other shelves in several ways. In particular, because more than one instance of an element type can be open at one time, more than one item of current elements can have the same key value, and name of is used rather than key of to access the name of opened elements.

A repeat over action can iterate over the set of opened elements, or a subset of them, by qualifying current elements with of. The repeat over action identifies the element: either the element identified by the of qualifier following repeat over current elements, or, if there is no such qualifier, the currently opened element. This element is identified when the repeat over commences. A repeat over action iterates over the set of opened elements consisting of the identified element and all of its ancestors.

A repeat over action that iterates over the current elements in the input processor buffers text written to the #markup-parser stream until the end of the loop. All text written to the markup parser within a repeat over current elements action is "buffered": none of the text is actually passed to OmniMark's markup parser until after the end of the repeat over action.

A "%q" format item, references to attributes, and element tests are not affected by a repeat over current elements action. These apply to the same element within the loop as they would outside the loop. In other words, the use of "%q" in the repeat over current elements action does not give the name of the element selected by the current iteration, but rather that of the most recently opened element.

An element alias-name can be used only as an "element-name" following the keyword current element.

current element alias-name can be used in several contexts within the repeat over current elements loop. It can be used to:

  • identify a specific opened element.
  • test the identity of the currently selected element.
  • get the name of the currently selected element.
  • get the number of opened elements, down to and including the currently selected element.

It is possible to use a name as both an element alias-name and a "real" element name. If such a name is used in any context other than immediately following the keyword current element, it refers to the element with that name and not to the alias-name.

Element alias names are subject to the setting of the namecase general declaration in the same way as all other element names, even though they are not, in a strict sense, SGML element names.

This code sample will close all of the elements which are currently open. Note, however, that because input to the parser is "buffered" while the loop is running, the elements won't actually be closed until the "repeat over" loop is complete.

  repeat over reversed current elements as this-element
  output "</"
  output name of current element this-element
  output ">"
  again

Copyright © OmniMark Technologies Corporation, 1988-1998.