1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Recursive/Resources/recursive_template.xhtml Fri Jan 27 17:00:33 2006 +0000
1.3 @@ -0,0 +1,39 @@
1.4 +<?xml version="1.0" encoding="iso-8859-1"?>
1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
1.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
1.7 +<html xmlns="http://www.w3.org/1999/xhtml"
1.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
1.9 +<head>
1.10 + <title>Recursive Example</title>
1.11 +</head>
1.12 +<body template:element="recursive">
1.13 +<form action="" method="POST">
1.14 +
1.15 +<!-- Template text between the start and the interesting part. -->
1.16 +
1.17 +<div template:element="list">
1.18 + <p>This is a list called <input template:attribute-field="name" name="..." type="text" value="..."/></p>
1.19 + <p>
1.20 + <input template:selector-field="remove" name="..." type="submit" value="Remove list"/>
1.21 + <input template:selector-field="add-item,item" name="..." type="submit" value="Add item to list"/>
1.22 + </p>
1.23 + <ul>
1.24 + <li template:element="item">
1.25 + <p>This is an item called <input template:attribute-field="name" name="..." type="text" value="..."/></p>
1.26 + <p>
1.27 + <input template:selector-field="remove" name="..." type="submit" value="Remove item"/>
1.28 + <input template:selector-field="add-list,list" name="..." type="submit" value="Add list here"/>
1.29 + </p>
1.30 + <p template:element="list">List goes here...</p>
1.31 + </li>
1.32 + </ul>
1.33 +</div>
1.34 +<p>
1.35 + <input template:selector-field="add-list,list" name="..." type="submit" value="Add list" />
1.36 +</p>
1.37 +
1.38 +<!-- Template text between the interesting part and the end. -->
1.39 +
1.40 +</form>
1.41 +</body>
1.42 +</html>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/Recursive/__init__.py Fri Jan 27 17:00:33 2006 +0000
2.3 @@ -0,0 +1,78 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"An example of recursive templates."
2.7 +
2.8 +import WebStack.Generic
2.9 +import XSLForms.Resources.WebResources
2.10 +import XSLForms.Utils
2.11 +import os
2.12 +
2.13 +# Resource classes.
2.14 +
2.15 +class RecursiveResource(XSLForms.Resources.WebResources.XSLFormsResource):
2.16 +
2.17 + "A resource providing a recursive hierarchy of editable fields."
2.18 +
2.19 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.20 + encoding = "utf-8"
2.21 + template_resources = {
2.22 + "recursive" : ("recursive_template.xhtml", "recursive_output.xsl")
2.23 + }
2.24 + init_resources = {
2.25 + "recursive" : ("recursive_template.xhtml", "recursive_input.xsl")
2.26 + }
2.27 +
2.28 + def respond_to_form(self, trans, form):
2.29 +
2.30 + """
2.31 + Respond to a request having the given transaction 'trans' and the given
2.32 + 'form' information.
2.33 + """
2.34 +
2.35 + parameters = form.get_parameters()
2.36 + documents = form.get_documents()
2.37 +
2.38 + # Ensure the presence of a document.
2.39 +
2.40 + if documents.has_key("recursive"):
2.41 + recursive = documents["recursive"]
2.42 + else:
2.43 + recursive = form.new_instance("recursive")
2.44 +
2.45 + # Add and remove elements according to the selectors found.
2.46 +
2.47 + selectors = form.get_selectors()
2.48 + XSLForms.Utils.remove_elements(selectors.get("remove"))
2.49 + XSLForms.Utils.add_elements(selectors.get("add-list"), "list")
2.50 + XSLForms.Utils.add_elements(selectors.get("add-item"), "item")
2.51 +
2.52 + # Initialise the document, adding enumerations/ranges.
2.53 +
2.54 + init_xsl = self.prepare_initialiser("recursive")
2.55 + recursive = self.get_result([init_xsl], recursive)
2.56 + #print recursive.toString("iso-8859-1")
2.57 +
2.58 + # Start the response.
2.59 +
2.60 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
2.61 +
2.62 + # Ensure that an output stylesheet exists.
2.63 +
2.64 + trans_xsl = self.prepare_output("recursive")
2.65 + stylesheet_parameters = {}
2.66 +
2.67 + # Complete the response.
2.68 +
2.69 + self.send_output(trans, [trans_xsl], recursive, stylesheet_parameters)
2.70 +
2.71 +# Site map initialisation.
2.72 +
2.73 +def get_site():
2.74 +
2.75 + "Return a simple Web site resource."
2.76 +
2.77 + # Get the main resource and the directory used by the application.
2.78 +
2.79 + return RecursiveResource()
2.80 +
2.81 +# vim: tabstop=4 expandtab shiftwidth=4