# HG changeset patch # User paulb # Date 1191627859 0 # Node ID ae9fb603ea93ab05a7d2a0afff4f2e58ed329a31 # Parent 4da6f6b98efad2582f009fcb8d040c603fc46a24 [project @ 2007-10-05 23:44:19 by paulb] Improved documentation about XSLT extension functions and their use. Updated release information. diff -r 4da6f6b98efa -r ae9fb603ea93 docs/advanced.html --- a/docs/advanced.html Fri Oct 05 23:43:58 2007 +0000 +++ b/docs/advanced.html Fri Oct 05 23:44:19 2007 +0000 @@ -11,12 +11,17 @@ data documents (or just general XML documents with no special connection to Web forms). However, since XSLForms templates build upon XSL transformations, it is also possible to employ certain XSL -techniques to present the information in various different ways.
When prepared, XSLForms templates are converted to XSL stylesheets, and +techniques to present the information in various different ways.
+ +When prepared, XSLForms templates are converted to XSL stylesheets, and when form data is displayed, such XSL stylesheets are used to transform the form data to a representation which looks like the original template, but with different parts of the template populated with the form data. The process can be illustrated as follows:
+Since the stylesheet is based on XSL, which is a rich language in its own right, advanced template design techniques can involve some of the features of XSL - at least those which do not -affect the simplicity or general structure of our templates.
One +affect the simplicity or general structure of our templates.
+ +One area where XSL features are already employed to affect the final output in XSLForms is in the toolkit's use of template extension functions and special variables - the latter being used in the output production process. For example, we might decide to use the lower level -template functions to present the value of an attribute:
<span template:attribute="some-attribute" template:value="$this-value">xxx</span>
In the above example, we reference the special variable $this-value
which refers to the value of some-attribute
. An example of template functions in use looks like this:
<span id="{template:this-element()}">xxx</span>
In the above example, we invoke the template function template:this-element
+template functions to present the value of an attribute:
<span template:attribute="some-attribute" template:value="$this-value">xxx</span>+ +
In the above example, we reference the special variable $this-value
which refers to the value of some-attribute
. An example of template functions in use looks like this:
<span id="{template:this-element()}">xxx</span>+ +
In the above example, we invoke the template function template:this-element
in order to create a unique identifier in the final output. Since we
-use the function inside an attribute which is not prefixed with template
, we must enclose the expression between {
and }
characters.
Since
+use the function inside an attribute which is not prefixed with template
, we must enclose the expression between {
and }
characters.
Since the above template extension functions and variables are merely special in the sense that XSLForms provides them to produce its output, and since they are accessed in the stylesheet using normal XSL-based mechanisms, there is no technical barrier to using other kinds of valid XSL (or more precisely, XPath) expressions in cases such as those given above. The -rules for using such expressions in attributes are straightforward:
template
can contain expressions as one would write them normally.{
and }
characters so that the expression is evaluated and replaced with the result in the final output.Here is a trivial example of the usage of an XPath expression, based on one of the above examples:
<span template:attribute="some-attribute" template:value="string-length($this-value)">xxx</span>
In the above example, we invoke the standard XPath function string-length
in order to produce within the span
element the length of the value of some-attribute
(instead of the actual value).
More +rules for using such expressions in attributes are straightforward:
+ +template
can contain expressions as one would write them normally.{
and }
characters so that the expression is evaluated and replaced with the result in the final output.Here is a trivial example of the usage of an XPath expression, based on one of the above examples:
+ +<span template:attribute="some-attribute" template:value="string-length($this-value)">xxx</span>+ +
In the above example, we invoke the standard XPath function string-length
in order to produce within the span
element the length of the value of some-attribute
(instead of the actual value).
More interesting applications of XPath expressions and non-XSLForms functions arise when using more of the potential of XPath to select arbitrary elements and attributes and to perform calculations on the selected nodes. The following example originates from the Configurator -example application:
<span template:value="sum(/configuration//*[@value-is-set]/@price) + sum(/configuration//*[@value = ../@value]/@price)"></span>
This complicated expression, to be inserted within the span
element, finds all elements in the system configuration having the value-is-set
+example application:
<span template:value="sum(/configuration//*[@value-is-set]/@price) + sum(/configuration//*[@value = ../@value]/@price)"></span>+ +
This complicated expression, to be inserted within the span
element, finds all elements in the system configuration having the value-is-set
attribute and adds their prices together; this total is combined with
the sum of the prices from all elements marked as selected in their
respective lists. In other words, it gets the total of all selected
-components and inserts it into the final output.