XSLTForms/XSLTForms only Extensions

Configuration edit

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

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 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

Sample configuration file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template name="config">
		<options>
			<nocss><!-- When existent, no css-conversion hapens. -->
		</options>
		<properties> <!--  Accessible at run time from within model('xf-model-config')/instance('xf-instance-config'). -->
			<language>navigator</language> <!-- navigator or default -->
			<calendar.day0>Mon</calendar.day0>
			<calendar.day1>Tue</calendar.day1>
			<calendar.day2>Wed</calendar.day2>
			<calendar.day3>Thu</calendar.day3>
			<calendar.day4>Fri</calendar.day4>
			<calendar.day5>Sat</calendar.day5>
			<calendar.day6>Sun</calendar.day6>
			<calendar.initDay>6</calendar.initDay>
			<calendar.month0>January</calendar.month0>
			<calendar.month1>February</calendar.month1>
			<calendar.month2>March</calendar.month2>
			<calendar.month3>April</calendar.month3>
			<calendar.month4>May</calendar.month4>
			<calendar.month5>June</calendar.month5>
			<calendar.month6>July</calendar.month6>
			<calendar.month7>August</calendar.month7>
			<calendar.month8>September</calendar.month8>
			<calendar.month9>October</calendar.month9>
			<calendar.month10>November</calendar.month10>
			<calendar.month11>December</calendar.month11>
			<format.date>MM/dd/yyyy</format.date>
			<format.datetime>MM/dd/yyyy hh:mm:ss</format.datetime>
			<format.decimal>.</format.decimal>
			<status>... Loading ...</status>
		</properties>
		<extensions> 
		<!-- 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. -->
		</extensions>
	</xsl:template>
</xsl:stylesheet>

Processing Instructions edit

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

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

Elements edit

  • 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

Extension functions supported by XSLTForms:

User-Defined Functions edit

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"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:nfunc="http://example.net/xforms/new-functions/"
    nfunc:bogus="Workaround for FF's bug: https://bugzilla.mozilla.org/show_bug.cgi?id=94270"
>
 <head>
  <title>User-Defined XPath functions</title>

This is for old versions of XsltForms:

  <script>
    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"; 
            } 
        );
  </script>

This works for new versions of XsltForms:

  <script>
    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"; 
            } 
        );
  </script>
 </head>
 <body>
  <p>
    Hello to <xf:output value="concat('My ', nfunc:new-func())" />.
  </p>
 </body>
</html>

Arithmetic expressions edit

Objects in the javascript: pseudo-URL in xf:load/xf:resource@value edit

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:

  XSLTFormsContext.elementId

Using TinyMCE as mixed-content editor edit

See separate page on this topic.