跳轉到內容

XSLTForms/XSLTForms 擴充套件

來自華夏公益教科書,自由的教科書

影響 XSLTForms 變換的配置選項來自以下來源,其中每個選項的值是首先找到的值

  1. 外部定義的 XSLT 引數,
  2. config_LANG.xsl檔案,
  3. 處理指令(PI)。

XSLT 引數

[編輯 | 編輯原始碼]

xmlns="http://www.w3.org/1999/XSL/Transform"下,接受以下 xsl-params

  • baseuri:如果未指定,則預設為xsltforms.xsl的基名。
  • xsltforms_caller:
  • xsltforms_config:一個節點集,其子節點是配置<properties>元素,這些元素將被複制到結果 xforms-page 上。預設為在config.xsl檔案中指定的值。
  • xsltforms_debug: 'yes'或任何其他值。如果未指定,則假定為無除錯模式。
  • xsltforms_lang:選擇語言檔案時使用的字尾config_<SUFFIX>.xsl,該檔案指定訊息、日曆和其他本地化/國際化資訊。

請注意xsltforms_configxsltforms_debugxsltforms_lang引數將進一步應用於包含 xsl-stylesheet PI 的任何後續文件的轉換,無論是在使用replace="all"提交時,還是在 SVG 或應用transform()擴充套件函式時。

配置檔案config.xsl

[編輯 | 編輯原始碼]

配置檔案示例

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

處理指令

[編輯 | 編輯原始碼]

xforms 頁面可以指定以下處理指令(PI)作為配置引數

  • xsltforms-options:它接受 2 個偽屬性,例如
   <?xsltforms-options debug="yes" lang="en"?>
  • css-conversion:例如
   <?css-conversion no?>
  • xforms:tree:內容模型(xforms:label?, xforms:item/xforms:label*)
  • xforms:setnode:接受 ref 屬性來繫結節點,innerouter 屬性,其值為一個或多個 XML 節點的 XML 序列化;innerouter 屬性被解析,生成的節點將替換由 ref 繫結的節點的子節點,或者替換節點本身。(參見 setnode 的單獨頁面。)

XSLTForms 支援的擴充套件函式

使用者自定義函式

[編輯 | 編輯原始碼]

以下是如何定義使用者自定義 XPath 函式的示例

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

適用於舊版本的 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>

適用於新版本的 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>

算術表示式

[編輯 | 編輯原始碼]

javascript 中的物件偽 URL 在xf:load/xf:resource@value

[編輯 | 編輯原始碼]

偽 URL 在偽 URL 在屬性中使用時,包含的<xf:load>元素的 id 由以下 js 物件屬性包含

  XSLTFormsContext.elementId

使用 TinyMCE 作為混合內容編輯器

[編輯 | 編輯原始碼]

參見 關於此主題的單獨頁面

華夏公益教科書