1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Candidate/Resources/candidate_init.xsl Fri Sep 30 22:54:17 2005 +0000
1.3 @@ -0,0 +1,59 @@
1.4 +<?xml version="1.0" encoding="utf-8"?>
1.5 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1.6 + version="1.0">
1.7 +
1.8 + <xsl:param name="status"/>
1.9 +
1.10 + <!-- Add or process status elements inside status elements. -->
1.11 +
1.12 + <xsl:template match="candidate">
1.13 + <!-- Copy the element and its contents. -->
1.14 + <xsl:copy>
1.15 + <xsl:apply-templates select="@*"/>
1.16 + <identity>
1.17 + <xsl:apply-templates select="identity/@*"/>
1.18 + </identity>
1.19 + <!-- Look for a status element. -->
1.20 + <xsl:call-template name="status"/>
1.21 + <skills>
1.22 + <xsl:apply-templates select="skills/*"/>
1.23 + </skills>
1.24 + <qualifications>
1.25 + <xsl:apply-templates select="qualifications/*"/>
1.26 + </qualifications>
1.27 + <experience>
1.28 + <xsl:apply-templates select="experience/*"/>
1.29 + </experience>
1.30 + </xsl:copy>
1.31 + </xsl:template>
1.32 +
1.33 + <!-- Investigate status elements. -->
1.34 +
1.35 + <xsl:template name="status">
1.36 + <!-- Make the element. -->
1.37 + <status>
1.38 + <xsl:apply-templates select="status/@*"/>
1.39 + <xsl:call-template name="status-enum"/>
1.40 + </status>
1.41 + </xsl:template>
1.42 +
1.43 + <!-- Add to status elements the range of acceptable values. -->
1.44 +
1.45 + <xsl:template name="status-enum">
1.46 + <!-- Find all values in the range and add them. -->
1.47 + <xsl:for-each select="$status/status/status-enum">
1.48 + <xsl:copy>
1.49 + <xsl:apply-templates select="@*"/>
1.50 + </xsl:copy>
1.51 + </xsl:for-each>
1.52 + </xsl:template>
1.53 +
1.54 + <!-- Replicate unknown elements. -->
1.55 +
1.56 + <xsl:template match="@*|*|node()">
1.57 + <xsl:copy>
1.58 + <xsl:apply-templates select="@*|*|node()"/>
1.59 + </xsl:copy>
1.60 + </xsl:template>
1.61 +
1.62 +</xsl:stylesheet>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/Candidate/Resources/candidate_status.xml Fri Sep 30 22:54:17 2005 +0000
2.3 @@ -0,0 +1,7 @@
2.4 +<?xml version="1.0"?>
2.5 +<status>
2.6 + <status-enum value="Not working"/>
2.7 + <status-enum value="Working, looking passively"/>
2.8 + <status-enum value="Working, looking actively"/>
2.9 + <status-enum value="Other"/>
2.10 +</status>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/Common/Candidate/Resources/candidate_template.xhtml Fri Sep 30 22:54:17 2005 +0000
3.3 @@ -0,0 +1,114 @@
3.4 +<?xml version="1.0" encoding="iso-8859-1"?>
3.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3.7 +<html xmlns="http://www.w3.org/1999/xhtml"
3.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
3.9 +<head>
3.10 + <title>Candidate</title>
3.11 +</head>
3.12 +<body template:element="candidate">
3.13 +<form action="" method="POST">
3.14 +
3.15 +<h1>Candidate Details</h1>
3.16 +
3.17 +<table border="0" cellspacing="0" cellpadding="5">
3.18 + <tbody>
3.19 + <tr>
3.20 + <th colspan="2">General</th>
3.21 + </tr>
3.22 + <tr template:element="identity">
3.23 + <th>Name</th>
3.24 + <td>
3.25 + <input template:attribute-field="name" type="text" />
3.26 + </td>
3.27 + </tr>
3.28 + <tr>
3.29 + <th>Work status</th>
3.30 + <td>
3.31 + <select template:multiple-choice-field="status,value">
3.32 + <option template:multiple-choice-value="status-enum,value,selected"/>
3.33 + </select>
3.34 + </td>
3.35 + </tr>
3.36 + <tr>
3.37 + <th colspan="2">Skills</th>
3.38 + </tr>
3.39 + <tr template:element="skills,skill">
3.40 + <th>Skill</th>
3.41 + <td>
3.42 + <input template:attribute-field="value" type="text" />
3.43 + <input template:selector-field="remove" type="submit" value="Remove" />
3.44 + </td>
3.45 + </tr>
3.46 + <tr>
3.47 + <th></th>
3.48 + <td>
3.49 + <input template:selector-field="add-skill" type="submit" value="Add" />
3.50 + </td>
3.51 + </tr>
3.52 + <tr>
3.53 + <th colspan="2">Qualifications</th>
3.54 + </tr>
3.55 + </tbody>
3.56 + <tbody template:element="qualifications,qualification">
3.57 + <tr>
3.58 + <th>Course/Diploma/Title</th>
3.59 + <td>
3.60 + <input template:attribute-field="title" type="text" />
3.61 + <input template:selector-field="remove" type="submit" value="Remove" />
3.62 + </td>
3.63 + </tr>
3.64 + <tr>
3.65 + <th>Grade/Level/Class</th>
3.66 + <td>
3.67 + <input template:attribute-field="grade" type="text" />
3.68 + </td>
3.69 + </tr>
3.70 + <tr>
3.71 + <th>Institution</th>
3.72 + <td>
3.73 + <input template:attribute-field="institution" type="text" />
3.74 + </td>
3.75 + </tr>
3.76 + </tbody>
3.77 + <tbody>
3.78 + <tr>
3.79 + <th></th>
3.80 + <td>
3.81 + <input template:selector-field="add-qualification" type="submit" value="Add" />
3.82 + </td>
3.83 + </tr>
3.84 + </tbody>
3.85 + <tbody>
3.86 + <tr>
3.87 + <th colspan="2">Experience</th>
3.88 + </tr>
3.89 + </tbody>
3.90 + <tbody template:element="experience,employment">
3.91 + <tr>
3.92 + <th>Employment</th>
3.93 + <td>
3.94 + From <input template:attribute-field="from" type="text" />
3.95 + to <input template:attribute-field="to" type="text" />
3.96 + <input template:selector-field="remove" type="submit" value="Remove" />
3.97 + </td>
3.98 + </tr>
3.99 + <tr>
3.100 + <th>Employer</th>
3.101 + <td>
3.102 + <input template:attribute-field="employer" type="text" />
3.103 + </td>
3.104 + </tr>
3.105 + </tbody>
3.106 + <tbody>
3.107 + <tr>
3.108 + <th></th>
3.109 + <td>
3.110 + <input template:selector-field="add-employment" type="submit" value="Add" />
3.111 + </td>
3.112 + </tr>
3.113 +</table>
3.114 +
3.115 +</form>
3.116 +</body>
3.117 +</html>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/examples/Common/Candidate/__init__.py Fri Sep 30 22:54:17 2005 +0000
4.3 @@ -0,0 +1,110 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +"A job candidate editing application."
4.7 +
4.8 +import WebStack.Generic
4.9 +import XSLForms.Resources
4.10 +import XSLForms.Utils
4.11 +import os
4.12 +
4.13 +# Site map imports.
4.14 +
4.15 +from WebStack.Resources.ResourceMap import MapResource
4.16 +from WebStack.Resources.Static import DirectoryResource
4.17 +
4.18 +# Resource classes.
4.19 +
4.20 +class CandidateResource(XSLForms.Resources.XSLFormsResource):
4.21 +
4.22 + "A resource providing editing facilities for a job candidate profile."
4.23 +
4.24 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
4.25 + encoding = "utf-8"
4.26 + template_resources = {
4.27 + "candidate" : ("candidate_template.xhtml", "candidate_output.xsl")
4.28 + }
4.29 + transform_resources = {
4.30 + "init" : ["candidate_init.xsl"]
4.31 + }
4.32 + document_resources = {
4.33 + "status" : "candidate_status.xml"
4.34 + }
4.35 + in_page_resources = {
4.36 + }
4.37 +
4.38 + def respond_to_form(self, trans, form):
4.39 +
4.40 + """
4.41 + Respond to a request having the given transaction 'trans' and the given
4.42 + 'form' information.
4.43 + """
4.44 +
4.45 + in_page_resource = self.get_in_page_resource(trans)
4.46 + parameters = form.get_parameters()
4.47 + documents = form.get_documents()
4.48 +
4.49 + # Ensure the presence of a document.
4.50 +
4.51 + if documents.has_key("candidate"):
4.52 + candidate = documents["candidate"]
4.53 + else:
4.54 + candidate = form.new_instance("candidate")
4.55 +
4.56 + # Add and remove elements according to the selectors found.
4.57 +
4.58 + selectors = form.get_selectors()
4.59 + XSLForms.Utils.remove_elements(selectors.get("remove"))
4.60 + XSLForms.Utils.add_elements(selectors.get("add-skill"), "skill", "skills")
4.61 + XSLForms.Utils.add_elements(selectors.get("add-qualification"), "qualification", "qualifications")
4.62 + XSLForms.Utils.add_elements(selectors.get("add-employment"), "employment", "experience")
4.63 +
4.64 + # Transform, adding enumerations/ranges.
4.65 +
4.66 + init_xsl = self.prepare_transform("init")
4.67 + status_xml = self.prepare_document("status")
4.68 + candidate = self.get_result(init_xsl, candidate, references={"status" : status_xml})
4.69 +
4.70 + # Start the response.
4.71 +
4.72 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
4.73 +
4.74 + # Define the stylesheet parameters.
4.75 +
4.76 + stylesheet_parameters = {}
4.77 +
4.78 + # Ensure that an output stylesheet exists.
4.79 +
4.80 + if in_page_resource in self.in_page_resources.keys():
4.81 + trans_xsl = self.prepare_fragment("candidate", in_page_resource)
4.82 + element_path = parameters.get("element-path", [""])[0]
4.83 + stylesheet_parameters["element-path"] = element_path
4.84 + else:
4.85 + trans_xsl = self.prepare_output("candidate")
4.86 +
4.87 + # Complete the response.
4.88 +
4.89 + self.send_output(trans, [trans_xsl], candidate, stylesheet_parameters)
4.90 +
4.91 +# Site map initialisation.
4.92 +
4.93 +def get_site():
4.94 +
4.95 + "Return a simple Web site resource."
4.96 +
4.97 + # Get the main resource and the directory used by the application.
4.98 +
4.99 + candidate_resource = CandidateResource()
4.100 + directory = candidate_resource.resource_dir
4.101 +
4.102 + # Make a simple Web site.
4.103 +
4.104 + resource = MapResource({
4.105 + # Static resources:
4.106 + #"scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}),
4.107 + # Main page and in-page resources:
4.108 + None : candidate_resource
4.109 + })
4.110 +
4.111 + return resource
4.112 +
4.113 +# vim: tabstop=4 expandtab shiftwidth=4