What is XML Sapiens?

CMS 4 min read
ui-image What is XML Sapiens?

In 1995, Vignette introduced the first commercial Content Management System (CMS). Since then, the number of commercial CMS products has continued to grow, and the term “CMS” itself has become widely recognized across the industry.

Over the years, many open standards have been developed to help structure website content and separate content from presentation. Yet most CMS products still do not fully embrace these standards. One example is XSLT, a technology that has existed for years and allows documents to be generated from separate sources: an XML file containing structured content and an XSL template describing how that content should be presented.

Document generation can even occur on the client side. A browser only needs an XML document and a reference to an XSL template. It can then render the page exactly as intended by the designers. While the content of individual pages varies, the ways in which that content is presented are usually limited to a relatively small number of templates.

This makes XSLT an attractive technology for CMS development. A presentation template can be written once and reused across many pages. In theory, it seems like an ideal solution.

In practice, several factors have limited widespread adoption. Psychological inertia is only one of them. Developing site functionality with XSLT is often labor-intensive. XSL templates also tend to be tightly coupled to the structure of the underlying XML documents, reducing flexibility and making long-term maintenance more difficult.

As a result, XSLT remains conceptually elegant but often cumbersome in real-world projects. This has encouraged developers to look for alternatives that retain the benefits of open standards while providing a more practical development model. One such solution is the declarative language XML Sapiens.

How XML Sapiens Works

Like XSLT, XML Sapiens associates each document with a template. A template may contain any presentation code, such as HTML, along with XML Sapiens instructions.

Templates can include other template files using the sapi:include directive, similar in concept to the XInclude standard:

<sapi:include href="template_file" parse="template" />

Other XML Sapiens instructions are used to deliver content and functional components into a document.

The primary goal of XML Sapiens is to separate content structure definitions from functionality definitions. This allows developers to create reusable libraries of content structures and functional building blocks that can later be assembled into complete websites.

XML Sapiens and Data

XML Sapiens introduces the concept of interface states. This allows a page to display different sets of data depending on external conditions.

For example, an authenticated user may see one set of fields, while a guest user sees another. The field configuration for each state is defined in a separate XML document.

A field set can be included using:

<sapi:include
    href="fieldset_file"
    parse="fieldset"
    state="a2" />

Field sets contain data delivery instructions that associate data identifiers with field types defined in external XML documents.

<sapi:apply
    name="qc.identifier.value"
    type="field_type"
    href="field_type_definition" />

Like field sets, field type definitions may contain state-specific configurations. For example, if the system defines “administration” and “content delivery” states, the same data can be displayed as an editable form in one state and as rendered content in another.

Content Markup

Content structures are described independently from their presentation and processing logic. This separation allows content definitions to be reused across multiple projects and contexts.

Figure 1

XML Sapiens and Functionality

Page templates may also contain instructions that invoke functional scripts. The logic behind these scripts is described in separate XML files.

<sapi:apply
    name="ddc.menu.value"
    href="script_file" />

A functional algorithm description document (DDC) contains conditional logic similar to that found in XSLT. The DDC syntax can also invoke CMS applications that return data streams for further processing.

The following example illustrates a simplified DDC structure:

<sapi:ddc name="sample">
    <sapi:choose>
        <sapi:when exp="eq(this_record_id.value,0)">
            <sapi:for-each select="cms_application()" name="enum">

                <sapi:params>
                    <sapi:param name="param1">value1</sapi:param>
                    <sapi:param name="param2">value2</sapi:param>
                </sapi:params>

                <sapi:ifempty>Records not found</sapi:ifempty>
                <sapi:fallback>CMS application error</sapi:fallback>

                <sapi:choose>
                    <sapi:when exp="gt(this.this.variable.value,0)">
                        <sapi:code>
                            Sample code
                        </sapi:code>
                    </sapi:when>
                </sapi:choose>

            </sapi:for-each>
        </sapi:when>
    </sapi:choose>
</sapi:ddc>

Functional scripts can also accept parameters, making them reusable in different contexts:

<sapi:apply
    name="ddc.menu.value"
    href="http://site.com/ddc/menu.xml">

    <sapi:param name="param1">value1</sapi:param>
    <sapi:param name="param2">value2</sapi:param>

</sapi:apply>
Figure 2

Functional Markup

XML Sapiens makes it possible to build reusable definitions for data structures, content field types, and application functionality. These components can then be assembled as needed when building a website.

The ability to reuse functional and structural elements reduces development time and minimizes the need for low-level system programming. XML Sapiens is also platform-independent and can be integrated into CMS platforms written in virtually any programming language.

The language has existed for more than a year, and a second version has recently been released. This suggests continued development and growing maturity.

At present, only a handful of CMS platforms support XML Sapiens. If adoption increases, developers using different CMS products may eventually be able to exchange reusable functional components and solutions in a standardized way.