The Chain of Responsibility of the Ascending Wardens
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Delegation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Handler 1: The High Mage (Highest Priority) -->
<xsl:template match="threat[@level > 90]" priority="3">
<banished>
<xsl:text>The High Mage has utterly destroyed the threat: </xsl:text>
<xsl:value-of select="@name"/>
</banished>
</xsl:template>
<!-- Handler 2: The Adept (Medium Priority) -->
<xsl:template match="threat[@level > 50]" priority="2">
<!-- Partial handling, then passing it down the chain using xsl:next-match -->
<contained>
<xsl:text>The Adept slowed the entity. </xsl:text>
<xsl:next-match/>
</contained>
</xsl:template>
<!-- Handler 3: The Apprentice (Fallback Priority) -->
<xsl:template match="threat" priority="1">
<fled>
<xsl:text>The Apprentice ran away from: </xsl:text>
<xsl:value-of select="@name"/>
</fled>
</xsl:template>
<xsl:template match="/invasion">
<defense-log>
<xsl:apply-templates select="threat"/>
</defense-log>
</xsl:template>
</xsl:stylesheet>
Through the arcane power of template priority and the xsl:next-match instruction (introduced in XSLT 2.0), a weaver constructs a true Chain of Responsibility. An incoming XML node falls through the ether, caught first by the most specific, high-priority template. If that warden cannot fully dispatch the threat, xsl:next-match allows the node to plummet to the next applicable template in the hierarchy, gracefully delegating the response.
Runic Tags:
#xslt
#design-patterns
#behavioral
#chain-of-responsibility
#priority
#next-match