XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
A more fundamental concept than functions: units of code thatself-select

Hi Folks,

XSLT has xsl:template and xsl:function. On the surface they appear to be the same: you invoke a template rule using xsl:apply-templates and you invoke a function by dereferencing its name; you can pass parameters to both; both return values.

Clearly the idea of "function" is a fundamental concept in Computer Science.

It occurs to me that the functionality provided by template rules represent an even more fundamental concept. In fact, functions are merely a subset of the functionality provided by template rules.

Allow me to explain.

Consider these three template rules:

    <xsl:template match="Book[Publisher lt 1970]">

    <xsl:template match="Book[Publisher eq 1970]">

    <xsl:template match="Book[Publisher gt 1970]">

Suppose that Book is the context node and it has a Publisher child element with value 1970. With this apply-templates:

    <xsl:apply-templates select="." />

the second xsl:template rule will fire. Of the three template rules, the second one self-selected ("I meet the requisite conditions; I will now activate myself"). 

Template rules have the ability to self-select. Functions never self-select. They must always be explicitly called out.

Template rules can also be explicitly called out. Consider these revised templates: 

    <xsl:template match="*" mode="pre-1970">
        <param name="Book" />

    <xsl:template match="*" mode="eq-1970>
        <param name="Book" />

    <xsl:template match="*" mode="post-1970">
        <param name="Book" />

The second template can be explicitly called out:

    <xsl:template select="." mode="eq="1970">
        <xsl:with-param name="Book" select="." />

Each template rule is "named" using mode. Effectively the mode is used as the name of the template rule.

So template rules are units of code that can be either explicitly called out, or can self-select.

Functions are units of code that can only be explicitly called out.

The ability to create self-selecting units of code is very powerful. It resounds of decentralization, local-control, Complex Systems. Wow!

Are there other programming languages that support self-selecting units of code?

Do you agree that self-selecting units of code represents a more fundamental concept than functions?

/Roger




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS