Dynamator Pure HTML for every page generation technology.
           

Dynamator File for XSL.Text


Contents

Description
Patterns
Tips
Identification

DESCRIPTION

This document describes the language-specific format and code generation behavior of a Dynamator File with language specified as "xsl.text". This language plugin may be used to create XSL scripts for code generation.

A Dynamator File with a root element of "<dynamator language="xsl.text">" identifies a file containing transformations to be applied to an XML template in order to produce an XSL source file (i.e. a file with filetype ".xsl"). Dynamator applies the Dynamator file to an HTML or XML file (the "template") to create an XSL script that outputs a text file with structure corresponding to the template and behavior specified by the Dynamator file.

The only difference between language "xsl.text" and language "xsl" is in whitespace handling. Language "xsl.text" treats all whitespace as significant, and inserts <xsl:text> elements around textual content to force XSL to preserve all whitespace. Otherwise, there would be no way to prevent XSL from discarding whitespace between script elements.

For example, the XSL script fragment

<xsl:value-of select="'a'">  <xsl:value-of select="'b'">

generates

ab

But the Dynamator template fragment

<a/>  <b/>

generates (assuming the appropriate Dynamator tag elements)

a  b

XSL Elements

See the documentation for language="xsl".

Patterns

Prolog and epilog

As with language="xsl", the prolog and epilog must specify the start and end of the XSL file to be generated, specifically the <xsl:stylesheet> element and an <xsl:output method="text"> element.

File-level element

Although optional, it is often useful to begin and end an xsl.text template file with an XML element. For example, it can provide a way to specify which template files apply to a set of elements:

x.template
<module match="element-name">
template file 
...
</module>
x.dyn
...
<tag tag="module">
  <rename to="xsl:template"/<
</tag>
...

Selection

Selection is accomplished by specifying a tag element with a pseudocode-like name, replacing it with an XSL conditional:

x.template
...
<if-meaningful-condition-name>
conditional-text</if-meaningful-condition-name>
...
x.dyn
...
<tag tag="if-meaningful-condition-name">
  <discard-tag/>
  <if>xpath-conditional-expression</if>
</tag>
...

Choice

Selection of one of a set of alternatives may be supported by providing the boilerplate code in the example below for <xsl:choose> and <xsl:otherwise>, and by creating a tag element for each specific condition.

Because all whitespace in a template file is significant, care must be taken not to introduce whitespace between tags.

x.template
...
<choose
><when-meaningful-condition-name>
conditional template text</when-meaningful-condition-name-1
><otherwise>
default template text</otherwise
></choose>
...
x.dyn
...
<tag tag="choose">
  <rename to="xsl:choose"/>
</tag>

<tag tag="otherwise">
  <rename to="xsl:otherwise"/>
</tag>

<tag tag="when-meaningful-condition-name">
  <rename to="xsl:when"/>
  <attr name="test">
    <content>xpath-conditional-expression</content>
  </attr>
</tag>
...

HTML and XML elements

If a template contains HTML or XML elements to be propagated to the generated file, they must be explicitly retained using the pattern below.

HTML elements must be valid XML: end tags may not be omitted.

x.template
...
<p>
...
<p>
...
x.dyn
...
<tag tag="p">
  <discard-tag/>
  <before>&lt;p&gt;</before>
  <after>&lt;/p&gt;</after>
</tag>
...

HTML and XML entities

If the template contains ampersands, they must be explicitly replaced with elements.

x.template
...
if ( x <and> y )
...
x.dyn
...
<tag tag="and">
  <discard-tag/>
  <content>&amp;&amp;</content>
</tag>
...

Tips

Unmatched elements

To find template elements without a corresponding Dynamator file transformation:

===> grep "<[^x/!]" generated-xsl-file ...

Extra line breaks

To remove unwanted line breaks or whitespace, insert a comment that begins immediately before the whitespace and ends at the end of the whitespace.

x.template
...
    The natural ordering of objects of this type is determined by<!--
 --><choose
    ><when-has-one-sort-attr>
...

Common error messages

A message like Probably means
Only xsl:when and xsl:otherwise are allowed here There's whitespace between the choose, whens, or otherwise in an xsl:choose element.


SEE ALSO

dynamate, Dynamator File, Dynamator File for XSL


IDENTIFICATION
Author: Jay Dunning
Version: 1.5
Copyright: 2000-2004, Jay Dunning