PHP Classes

File: formCustomised.xsl

Recommend this page to a friend!
  Classes of Herman Veluwenkamp   xmlForm   formCustomised.xsl   Download  
File: formCustomised.xsl
Role: ???
Content type: text/plain
Description: XSL Stylesheet for Customised Example
Class: xmlForm
Generates a form in HTML.
Author: By
Last change:
Date: 22 years ago
Size: 7,142 bytes
 

Contents

Class file image Download
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:param name="isValidated"/> <!-- PASS IN PARAMETER INDICATING WHETHER FORM HAS BEEN VALIDATED --> <xsl:template match="form-config"> <form name='inputForm' onSubmit='return validate()'> <table cellpadding="2" cellspacing="0" border="0"> <xsl:for-each select="var"> <tr> <xsl:if test="validation-error"> <!-- IF VALIDATION-ERROR TAG ENCOUNTERED... --> <xsl:attribute name="class">formErrorRow</xsl:attribute> </xsl:if> <td align="right"><xsl:value-of select="description"/>: </td> <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td> <td><xsl:call-template name="form-element"/></td> <xsl:if test="$isValidated='yes'"> <!-- ONLY IF DATA HAS BEEN VALIDATED... --> <td> <xsl:choose> <xsl:when test="validation-error"> <xsl:attribute name="class">formError</xsl:attribute> <xsl:value-of select="validation-message"/> </xsl:when> <xsl:otherwise> <xsl:attribute name="class">formNoError</xsl:attribute> <xsl:text>okay</xsl:text> </xsl:otherwise> </xsl:choose> </td> </xsl:if> </tr> </xsl:for-each> <tr> <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td> <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td> <td> <input type="submit" value="ok" name="formAction" class="formButton"/> <input type="submit" value="cancel" name="formAction" class="formButton"/> <input type="submit" value="apply" name="formAction" class="formButton"/> </td> <xsl:if test="$isValidated='yes'"> <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td> </xsl:if> </tr> </table> </form> </xsl:template> <!-- ###### THIS TEMPLATE DOES NOT NORMALLY NEED TO BE EDITED --> <xsl:template name="form-element"> <xsl:choose> <xsl:when test='@type="text"'> <!-- TEXT FIELD --> <input> <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> <xsl:attribute name="type">text</xsl:attribute> <xsl:attribute name="value"><xsl:value-of select="value"/></xsl:attribute> <xsl:for-each select="html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each > </input> </xsl:when> <xsl:when test='@type="textarea"'> <!-- TEXTAREA FIELD --> <textarea> <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> <xsl:for-each select="html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each > <xsl:value-of select="value"/> </textarea> </xsl:when> <xsl:when test='@type="select"'> <!-- SINGLE SELECT FIELD --> <xsl:variable name="default"><xsl:value-of select="value"/></xsl:variable> <select> <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> <xsl:attribute name="type">text</xsl:attribute> <xsl:for-each select="html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each > <xsl:for-each select="option" > <option> <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute> <xsl:if test="$default=@value"> <xsl:attribute name="selected">yes</xsl:attribute> </xsl:if> <xsl:value-of select="."/> </option> </xsl:for-each> </select> </xsl:when> <xsl:when test='@type="multiselect"'> <!-- MULTIPLE SELECT FIELD --> <select> <xsl:attribute name="name"><xsl:value-of select="@name"/>[]</xsl:attribute> <xsl:attribute name="type">text</xsl:attribute> <xsl:attribute name="multiple">yes</xsl:attribute> <xsl:for-each select="html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each > <xsl:for-each select="option" > <option> <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute> <xsl:variable name="value"><xsl:value-of select="@value"/></xsl:variable> <xsl:for-each select="../value"> <!-- CAN HAVE MULTIPLE VALUES --> <xsl:if test=".=$value"> <xsl:attribute name="selected">yes</xsl:attribute> </xsl:if> </xsl:for-each> <xsl:value-of select="."/> </option> </xsl:for-each > </select> </xsl:when> <xsl:when test='@type="checkbox"'> <!-- CHECKBOX FIELD --> <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable> <!-- NAME OF FIELD --> <xsl:for-each select="option" > <xsl:variable name="value"><xsl:value-of select="@value"/></xsl:variable> <!-- VALUE OF FIELD --> <input> <xsl:attribute name="name"><xsl:value-of select="$name"/>[<xsl:number format="0"/>]</xsl:attribute> <xsl:attribute name="type">checkbox</xsl:attribute> <xsl:for-each select="../html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each > <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute> <xsl:for-each select="../value"> <!-- CAN HAVE MULTIPLE VALUES --> <xsl:if test=".=$value"> <xsl:attribute name="checked">yes</xsl:attribute> </xsl:if> </xsl:for-each> <xsl:value-of select="."/> </input> </xsl:for-each > </xsl:when> <xsl:when test='@type="radio"'> <!-- RADIO BUTTON FIELD --> <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable> <!-- NAME OF FIELD --> <xsl:variable name="default"><xsl:value-of select="value"/></xsl:variable> <xsl:for-each select="option"> <input> <xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute> <xsl:attribute name="type">radio</xsl:attribute> <xsl:for-each select="../html-display-option"> <xsl:attribute name="{@name}"><xsl:value-of select="@value"/></xsl:attribute> </xsl:for-each> <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute> <xsl:if test="$default=@value"> <xsl:attribute name="checked">yes</xsl:attribute> </xsl:if> <xsl:value-of select="."/> </input> </xsl:for-each> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet>