XSLTForms/XSLTForms only Extensions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Configuration[edit | edit source]

Configuration options affecting the XSLTForms transformation are taken from the sources below, where the value for each option is the one found first:

  1. externally-defined XSLT Parameters,
  2. config_LANG.xsl file,
  3. Processing-Instructions(PIs).

XSLT Params[edit | edit source]

Under the xmlns="http://www.w3.org/1999/XSL/Transform" the following xsl-params are accepted:

  • baseuri: If unspecified, defaults to the base-name of of the xsltforms.xsl href.
  • xsltforms_caller:
  • xsltforms_config: A nodeset having as child the configuration <properties> element that are to be copied on the result xforms-page. Defaults to the ones specified in config.xsl file.
  • xsltforms_debug: 'yes' or anything else. If unspecified, assumed no-debug.
  • xsltforms_lang: The suffix to use when selecting the language file config_<SUFFIX>.xsl which specifies messages, calendar and other localizations/I18Ns.

Note that xsltforms_config, xsltforms_debug, xsltforms_lang params are further applied to any subsequent transformations of documents containing a xsl-stylesheet PI, either on submission with replace="all" or SVGs, or when applying the transform() extension function.

Config File: config.xsl[edit | edit source]

Sample configuration file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template name="config">
			<nocss><!-- When existent, no css-conversion hapens. -->
		<properties> <!--  Accessible at run time from within model('xf-model-config')/instance('xf-instance-config'). -->
			<language>navigator</language> <!-- navigator or default -->
			<format.datetime>MM/dd/yyyy hh:mm:ss</format.datetime>
			<status>... Loading ...</status>
		<!-- JS script code to add. 
		   - When none of the following child elements exist, any elements here are copied 
		   - just after xsltforms.js and before init-scripts. 
			<beforeInit/>	<!-- Added in a separate <script> element, after xsltforms.js and before init-scipts. -->
			<onBeginInit/>	<!-- Added within init-code <script> at the beginning of initImpl() function, before any definitions. -->
			<onEndInit/>	<!-- Added within init-code <script> at the end of initImpl() function, after xforms.init() invocation. -->
			<afterInit/>	<!-- Added in a separate <script> element, after init-scripts. -->

Processing Instructions[edit | edit source]

A xforms page can specify the following processing-instructions(PI) that act as configuraton parameters:

  • xsltforms-options: It accepts 2 pseudo-attributes, sample:
   <?xsltforms-options debug="yes" lang="en"?>
  • css-conversion: sample:
   <?css-conversion no?>

Elements[edit | edit source]

  • xforms:tree: content-model: (xforms:label?, xforms:item/xforms:label*)
  • xforms:setnode: accepts ref attribute to bind a node, inner or outer attribute whose value is an XML serialization of one or more XML nodes; the inner or outer attribute is parsed, and the resulting nodes replace either the children of the node bound by ref, or the node itself. (See separate page for setnode.)

Functions[edit | edit source]

Extension functions supported by XSLTForms:

User-Defined Functions[edit | edit source]

Here is a sample of how to define user-defined XPath functions:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    nfunc:bogus="Workaround for FF's bug: https://bugzilla.mozilla.org/show_bug.cgi?id=94270"
  <title>User-Defined XPath functions</title>

This is for old versions of XsltForms:

    XPathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] =
        new XPathFunction(
            false,                       /* is accepting context as 1st-arg? */
            XPathFunction.DEFAULT_NONE,  /* context-form as 1st-arg, when (args.length == 0): [ DEFAULT_NONE | DEFAULT_NODE | DEFAULT_NODESET | DEFAULT_STRING ] */ 
            false,                       /* is returning nodes? */
            function() { 
              return "NEW FUNC"; 

This works for new versions of XsltForms:

    XsltForms_xpathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] =
        new XsltForms_xpathFunction(
            false,                       /* is accepting context as 1st-arg? */
            XsltForms_xpathFunction.DEFAULT_NONE,  /* context-form as 1st-arg, when (args.length == 0): [ DEFAULT_NONE | DEFAULT_NODE | DEFAULT_NODESET | DEFAULT_STRING ] */ 
            false,                       /* is returning nodes? */
            function() { 
              return "NEW FUNC"; 
    Hello to <xf:output value="concat('My ', nfunc:new-func())" />.

Arithmetic expressions[edit | edit source]

Objects in the javascript: pseudo-URL in xf:load/xf:resource@value[edit | edit source]

When the javascript: pseudo-URL is used within the xf:load/xf:resource@value attribute, the id of the enclosing <xf:load> element is contained by the following js object-property:


Using TinyMCE as mixed-content editor[edit | edit source]

See separate page on this topic.