The Iterator of the Infinite Loop
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Chronomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/grimoire">
<catalog>
<!-- The built-in Iterator mechanism in XSLT -->
<xsl:for-each select="spells/spell">
<!-- Sorting alters the iteration order dynamically -->
<xsl:sort select="@power" data-type="number" order="descending"/>
<entry index="{position()}" total="{last()}">
<name><xsl:value-of select="title"/></name>
<rank><xsl:value-of select="@power"/></rank>
</entry>
</xsl:for-each>
</catalog>
</xsl:template>
</xsl:stylesheet>
In XSLT, the Iterator pattern is fundamentally embedded within the language’s core via xsl:for-each and xsl:apply-templates. A mage does not manually maintain cursors or index counters; the XSLT engine traverses node-sets automatically. The functions position() and last() provide contextual awareness during the traversal, while xsl:sort effortlessly manipulates the temporal sequence of the iteration.
Runic Tags:
#xslt
#design-patterns
#behavioral
#iterator
#for-each
#traversal