You are here: Home > What's New > XML Declarative Programming

XML Declarative Programming

Rule-based Declarative Programming

In Essential XML (Chapter 5.1, p. 87), Aaron Skonnard and Martin Gudgin say that using XSLT template rules is declarative programming:

XSLT offers a powerful and flexible declarative programming model (similar to that of Prolog, Lisp, and Scheme). The declarative model is based on associating templates with patterns (or rules) relative to the input document.

Rule programming is declarative programming.

Venn diagram showing rule programming as a subset of declarative programming

XSLT is a rule-based declarative programming language.

Constraint-based Declarative Programming

A common programming task is to determine: does this data satisfy these constraints. For example, does each book have an author and an ISBN?

XML Schema, RELAX NG, and Schematron are XML languages for expressing constraints. Each of them describe the constraints; they don't prescribe how applications should process the constraints.

Constraint programming is declarative programming.

Venn diagram showing constraint programming as a subset of declarative programming

XML Schema, RELAX NG, and Schematron are constraint-based declarative programming languages.

Constraints are Rules

With XML Schema, RELAX NG, and Schematron you define rules. These rules express constraints on the structure of XML documents and constraints on the data.

Constraint programming is a type of rule programming.

Venn diagram showing constraint programming as a subset of rule programming, which is a subset of declarative programming

XHTML Declarative Programming

XHTML is a declarative programming language. An XHTML document describes the structure of the data; it doesn't prescribe how browsers (or any user agent) should process or display it. Ditto for SVG.

Venn diagram showing XHTML programming as a subset of declarative programming

Functional Declarative Programming (Definition-based)

XSLT 2.0 allows you to create functions. When functions are expressed as definitions then you are doing declarative programming. For example, consider the task of computing the area of a rectangle. If you write a function whose purpose is to define what an area is (Area = Height * Breadth), then you are doing declarative programming. If you write a function whose purpose is to compute the area (assign the variable, Area, the result of multiplying Height by Breadth), then you are doing imperative programming. In this particular example, the difference is subtle, but for more complex tasks, how functions are expressed may vary dramatically depending on whether you have a declarative mindset or an imperative mindset. With declarative programming the mindset is that of creating functions which define things. I'll refer to this as definition-based functional programming.

Definition-based functional programming is declarative programming.

Venn diagram showing definition-based functional programming as a subset of declarative programming

XSLT is a definition-based functional declarative programming language.

Translations

This article has been translated to Swedish by Eric Karlsson.

This article has been translated to Slovenian by Mary Orban. Here is the translation: http://www.pkwteile.ch/science/?p=23

Last Updated: February 29, 2020