Xslt Language

XSLT is an acronym for "Extensible Stylesheet Language Transformations". It is a language designed for transforming XML documents into other formats. There's no restriction on the format of the output, and in particular the somewhat less-well-known Xsl Formatting Objects portion of XSL is not a requirement.

XSLT is in the category Functional Programming Languages.

XSLT does not allow programmers to modify state. XSLT templates behave like pure functions. A light bulb goes on. Trying to write an XSL document with a procedural mind-set is certain to end in frustration. An interesting characteristic of XSLT is that the language syntax is defined to be well-formed, valid XML, which makes it verbose. Imagine the angle brackets as parentheses and it begins to look familiar.

The basic element of an XSL sheet is a template rule. The processor walks the document tree and attempts to match each node with a template rule. When a rule is matched, it is fired, typically resulting in generation of some new text and data, possibly transformed in other ways, and some information copied from the input document. The processor uses a complex syntax in the match patterns, and will recursively process nodes. Some elements can use the Xpath Language syntax.

A simple graphic of the XSL engine, from xml.com:

www.xml.com


Beginners corner

See Using XML Queries and Transformations from Wrox Sample chapter from Professional VB XML at www.developerfusion.com

Try doing some transformations - xslt.sitesfree.com


Known uses of XSLT

Jax Me's Bean Writer creates J2EE conformant entity beans for EJB from XML jaxme.sourceforge.net

The code for the Turing Machine stylesheet: www.unidex.com

Math Ml's ctop.xsl, which transforms "content elements" markup into "presentation elements" markup.

xcb.freedesktop.org uses XML to describe the Xwindow Protocol, and XSLT to transform it into specific language bindings.

Some references

Syntax and semantics:
www.w3.org

(Not) Looping in XSLT:
www.dpawson.co.uk

XSLT is Turing Complete:
www.unidex.com

Or it's missing some core FP? www.kuro5hin.org

XSL weaknesses:
www.xml.com


Is XSLT really one of the Functional Programming Languages?

No, apparently it is not. Lack of side effects and support for minimal function declarations do not a functional language make. How about function as values, easy and convenient functional composition (=support for lambda expressions), currying to name but a few features of functional languages. A functional language is about manipulating functions, not tree structures. I'm sure that many functional programming afficionados will find the comparison with such a clumsy language appalling.

I tend to think of it as a "rule-based" language - similar in concept to rule based expert systems. -- Jeff Grigg

Or, maybe it is:

"Dimitre Novatchev, author and XSL developer, has written an article demonstrating how functions (templates in XSL) can indeed be passed as a data type using XML namespaces in clever manner. Whether this qualifies templates as first class data types is certainly debatable, but Novatchev's technique makes it clear that XSL can operate as a weakly-typed functional language."

Some most general functional programming design patterns are supported by the FXSL functional programming library for XSLT:

The following articles describe the support for these design patterns and their use in specific problem areas:

"Dynamic Functions using FXSL: Composition, Partial Applications and Lambda Expressions"

"Casting the Dice with FXSL: Random Number Generation Functions in XSLT"

"An XSL Calculator: The Math Modules of FXSL"

"What kind of language is XSLT?" "XSLT is based on the concepts of functional programming in the tradition of languages such as Lisp, Haskell, and Scheme. A style sheet is made up of templates that are essentially pure functions -- each template defines a fragment of the output tree as a function of a fragment of the input tree, and produces no side effects." www-106.ibm.com .

"The Functional Programming Language XSLT - A proof through examples" www.topxml.com

Is XSLT a logic language?


Q I am looking for examples that help a complete novice to write a Xslt Language based transform that will convert plain text to Awiki Like Site compatible Html format. Is that trivial?

A The input to an XSLT stylesheet is XML, not plain text. You COULD wrap your plain text in a pair of tags, and use the pathetic string processing capabilities present, but it would probably be easier to use a Turing Machine.

That Turing Machine idea doesn't seem very helpful. Here, if you'd like to try Xslt for your solution, and you need to work with plain text, take a look at the EXSLT extensions at www.exslt.org - there are more helpful manipulation functions, especially string tokenizers.

Q Could XSLT be considered a member of the family of Homoiconic Languages? While both program and data are XML, it's not possible for a stylesheet to access its own code.

A



See original on c2.com