Module xmlrat_mini_xslt

Implements the "mxsl" subset/dialect of XSLT used for compiled XML templates.

Description

Implements the "mxsl" subset/dialect of XSLT used for compiled XML templates.

This template language is used in the -xml_record() attribute provided by xmlrat_parse_transform.

Introduction

The MXSL language is designed to look and feel a lot like XSLT, but with some modifications (due to the fact that the input data is Erlang records and not XML/XPath), and some abbreviations to make templates easier to read and write.

As well as the normal XSLT-style use of namespaced elements to substitute values (e.g. <mxsl:value-of field='...'/>), MXSL also supports using XML entities named after each record field for substitution.

A short example of an MXSL template, showing both an XSLT-style substitution and an entity substitution:

  <KeyInfo>
    <mxsl:if defined='name'>
      <KeyName><mxsl:value-of field='name'/></KeyName>
    </mxsl:if>
    <KeyType Algorithm='&algorithm;'/>
  </KeyInfo>

The mxsl: namespace URI is https://cooperi.net/xmlrat/mini-xslt/. Templates can either use the pre-defined namespace prefix mxsl:, or define their own in the regular way using xmlns:* attributes.

MXSL element reference

<mxsl:value-of>

Substitutes with the value of a record field. The mxsl:value-of element will be deleted, replaced with the record field's type-coerced value.

Attributes: Content:

<mxsl:attribute>

Adds an attribute to the parent element, with the new attribute's value set by a record field. Can also be nested inside a <mxsl:if> element (will add the attribute to the grandparent).

Attributes: Content:

<mxsl:if>

Conditionally applies or includes some elements if a record field is set to a value other than undefined, or set to boolean true.

Attributes: Content:

<mxsl:for-each>

Repeats a sub-tree of the document once for each element in a list. The current element is bound as a "fake" record field (and can be referenced by either <mxsl:value-of> etc or entities).

Attributes: Content:

<mxsl:tag>

Generates an element with a dynamic tag name based on a record field.

Attributes: Content:

The mxsl:field attribute will be elided from the output, but all other attributes of the tag will be inherited by the final output tag.

Entities

Within any element content or attribute value, entities may be used to refer to the value of record fields. The entity name matches the record field name exactly: e.g. &foobar; refers to the value of record field foobar.

When used in an attribute value, if the field is set to undefined, and the attribute value consists only of the field entity, the entire attribute will be elided from the output.

Generated by EDoc