Penguin

The MuenchianMethod is a technique in XSLT, which could probably also be applied to other data-centric Category:FunctionalProgrammingLanguages. It was developed/discovered by Steve Muench.

In XSLT a common problem is how to fire an action exactly once for each class of element seen. This is difficult in XSLT because it is a purely functional language and "remembering" that you've already seen an element of a class is impossible. There are certain highly recursive methods to solve the problem but these are incredibly inefficient, because (somewhat unusually for a functional language) XSLT is optimised not for recursion but for application of Templates to nodes in the XML tree.

The MuenchianMethod avoids this problem using a key defined to classify elements into a class. Keys in XSLT are like indexes in SQL -- they are efficient. A good introduction to the MuenchianMethod can be found on the web.

As an example, the following code creates a key called kName based on the name of each node. The template then matches only those nodes which are the first node in the key with that name.

... <xsl:key name="kName" match="*" use="name()"/> ... <xsl:template match="*[generate-id()

= generate-id(key('kName',

name() )[1?

)

]">

Element name: <xsl:value-of select="name()"/> <xsl:apply-templates/>

</xsl:template> ...