[Zope] - Zope, DTML and XML
Paul Prescod
paul@prescod.net
Sun, 13 Dec 1998 15:32:33 -0600
Of course Zope must eventually move into the XML world. Zope needs to do
templates. XSL also does templates. In fact templates are almost as
central to XSL as they are to Zope. I would suggest that Zope should use
XSL template syntax for DTML templates as far as is possible. In fact,
maybe when XSL becomes popular enough, it might make sense to describe the
interaction between Zope and the Python runtime in terms of XML
transformations. That's for the future, though.
In the meantime, the point is that the template syntax should be the same.
Here are the details from the current XSL spec:
"The value of an attribute of a literal result element is interpreted as
an attribute value template: it can contain string expressions contained
in curly braces ({})."
"Within a template, the xsl:value-of element can be used to compute
generated text, for example by extracting text from the source tree or by
inserting the value of a string constant. The xsl:value-of element does
this with a string expression that is specified as the value of the expr
attribute. String expressions can also be used inside attribute values of
literal result elements by enclosing the string expression in curly brace
({})."
"The xsl:value-of element is replaced by the value of the string
expression specified by the expr attribute. The expr attribute is
required."
"e.g. <xsl:value-of expr="attribute(first-name)"/>"
"In an attribute value that is interpreted as an attribute value template,
such as an attribute of a literal result element, string expressions can
be used by surrounding the string expression with curly braces ({}). The
attribute value template is instantiated by replacing the string
expression together with surrounding curly braces by the value of the
string expression.
The following example creates an IMG result element from a photograph
element in the source; the value of the SRC attribute of the IMG element
is computed from the value of the image-dir constant and the content of
the href child of the photograph element; the value of the WIDTH attribute
of the IMG element is computed from the value of the the width attribute
of the size child of the photograph element:
<xsl:define-constant name="image-dir" value="/images"/>
<xsl:template match="photograph">
<IMG SRC="{constant(image-dir)}/{href}" WIDTH="{size/attribute(width)}"/>
</xsl:template>
With this source
<photograph>
<href>headquarters.jpg</href>
<size width="300"/>
</photograph>
the result would be
<IMG SRC="/images/headquarters.jpg" WIDTH="300"/>
When an attribute value template is instantiated, a double left or right
curly brace outside a string expression will be replaced by a single curly
brace. It is an error if a right curly brace occurs in an attribute value
template outside a string expression without being followed by a second
right curly brace; an XSL processor may signal the error or recover by
treating the right curly brace as if it had been doubled. A right curly
brace inside an AttributeValue in a string expression is not recognized as
terminating the string expression."
http://www.w3.org/TR/WD-xsl
Paul Prescod - ISOGEN Consulting Engineer speaking for only himself
http://itrc.uwaterloo.ca/~papresco
"Sports utility vehicles are gated communities on wheels" - Anon