✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Prototype of the Doppelgänger

Creating new objects by cloning a prototypical instance, allowing for deep copying and localized mutations in XML.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Cloning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- The Identity Transform: The ultimate cloner -->
    <xsl:template match="@*|node()" mode="clone">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" mode="clone"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/grimoire">
        <expanded-grimoire>
            <!-- Clone the original spell exactly -->
            <xsl:apply-templates select="spell" mode="clone"/>
            
            <!-- Clone the spell but mutate it slightly (Prototype mutation) -->
            <xsl:apply-templates select="spell" mode="mutate-clone"/>
        </expanded-grimoire>
    </xsl:template>

    <!-- Mutating the clone: intercepting specific nodes during the cloning process -->
    <xsl:template match="@*|node()" mode="mutate-clone">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" mode="mutate-clone"/>
        </xsl:copy>
    </xsl:template>

    <!-- The mutation rule: changing the power level in the cloned version -->
    <xsl:template match="@power" mode="mutate-clone">
        <xsl:attribute name="power">
            <xsl:value-of select=". * 10"/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

The Prototype pattern is perhaps the most famous incantation in XSLT, commonly known as the “Identity Transform”. By deep-copying an entire XML sub-tree and selectively overriding specific templates within that mode, a weaver can forge a near-exact replica of a magical artifact with highly specific enhancements or corruptions.

Runic Tags: #xslt #design-patterns #creational #prototype #identity-transform