ivelin 2002/09/22 20:58:30 Modified: src/webapp/samples/stylesheets/xmlform xmlform2html.xsl Log: minor update Mostly comments Revision Changes Path 1.2 +48 -28 xml-cocoon2/src/webapp/samples/stylesheets/xmlform/xmlform2html.xsl Index: xmlform2html.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/samples/stylesheets/xmlform/xmlform2html.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- xmlform2html.xsl 2 Jul 2002 13:06:41 -0000 1.1 +++ xmlform2html.xsl 23 Sep 2002 03:58:30 -0000 1.2 @@ -26,8 +26,7 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002" -> + xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"> <xsl:output method = "html" omit-xml-declaration = "yes" /> @@ -36,51 +35,68 @@ <xsl:apply-templates /> </xsl:template> + <xsl:template match="xf:form"> - <form method="POST"> + <form> <xsl:copy-of select="@*"/> + + <!-- the xf:form/@view attributed is sent back to the server as a hidden field --> <input type="hidden" name="cocoon-xmlform-view" value="{@view}"/> + + <!-- render the child form controls --> <xsl:apply-templates /> + </form> </xsl:template> + <xsl:template match="xf:output"> [<xsl:value-of select="xf:value/text()"/>] </xsl:template> + <xsl:template match="xf:textbox"> + <!-- the ref attribute is assigned to html:name, which is how it is linked to the model --> <input name="{@ref}" type="textbox" value="{xf:value/text()}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <!-- copy all attributes from the original markup, except for "ref" --> + <xsl:copy-of select="@*[not(name()='ref')]"/> </input> </xsl:template> + <xsl:template match="xf:password"> <input name="{@ref}" type="password" value="{xf:value/text()}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> </input> </xsl:template> + <xsl:template match="xf:hidden"> <input name="{@ref}" type="hidden" value="{xf:value/text()}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> </input> </xsl:template> + <xsl:template match="xf:selectBoolean"> <input name="{@ref}" type="checkbox" value="true"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> <xsl:if test="xf:value/text() = 'true'"> <xsl:attribute name="checked"/> </xsl:if> </input> </xsl:template> + <xsl:template match="xf:selectOne | xf:selectOne[@selectUIType='listbox']"> <select name="{@ref}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> + <!-- all currently selected nodes are listed as value elements --> <xsl:variable name="selected" select="xf:value"/> <xsl:for-each select="xf:item"> <option value="{xf:value}"> + <!-- If the current item value matches one of the selected values --> + <!-- mark it as selected in the listbox --> <xsl:if test="$selected = xf:value"> <xsl:attribute name="selected"/> </xsl:if> @@ -89,13 +105,14 @@ </xsl:for-each> </select> </xsl:template> + <xsl:template match="xf:selectOne[@selectUIType='radio']"> - <xsl:variable name="selected" select="xf:value"/> - <xsl:variable name="ref" select="@ref"/> + <xsl:variable name="selected" select="xf:value"/> + <xsl:variable name="ref" select="@ref"/> <xsl:for-each select="xf:item"> <input name="{$ref}" type="radio" value="{xf:value}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> <xsl:if test="xf:value = $selected"> <xsl:attribute name="checked"/> </xsl:if> @@ -107,28 +124,28 @@ <xsl:template match="xf:selectMany | xf:selectMany[@selectUIType='listbox']"> - <xsl:variable name="selected" select="xf:value"/> - <select name="{@ref}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> - <xsl:attribute name="multiple"/> - <xsl:for-each select="xf:item"> - <option value="{xf:value}"> - <xsl:if test="xf:value = $selected"> - <xsl:attribute name="selected"/> - </xsl:if> - <xsl:value-of select="xf:caption"/> - </option> - </xsl:for-each> - </select> + <xsl:variable name="selected" select="xf:value"/> + <select name="{@ref}"> + <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:attribute name="multiple"/> + <xsl:for-each select="xf:item"> + <option value="{xf:value}"> + <xsl:if test="xf:value = $selected"> + <xsl:attribute name="selected"/> + </xsl:if> + <xsl:value-of select="xf:caption"/> + </option> + </xsl:for-each> + </select> </xsl:template> <xsl:template match="xf:selectMany[@selectUIType='checkbox']"> - <xsl:variable name="selected" select="xf:value"/> - <xsl:variable name="ref" select="@ref"/> + <xsl:variable name="selected" select="xf:value"/> + <xsl:variable name="ref" select="@ref"/> <xsl:for-each select="xf:item"> <input name="{$ref}" type="checkbox" value="{xf:value}"> - <xsl:copy-of select="@*[not(name()='ref')]"/> + <xsl:copy-of select="@*[not(name()='ref')]"/> <xsl:if test="xf:value = $selected"> <xsl:attribute name="checked"/> </xsl:if> @@ -141,12 +158,15 @@ <xsl:template match="xf:submit"> + <!-- the id attribute of the submit control is sent to the server --> + <!-- as a conventional Cocoon Action parameter of the form cocoon-action-* --> <input name="cocoon-action-{@id}" type="submit" value="{xf:caption/text()}"> - <xsl:copy-of select="@*[not(name()='id')]"/> + <xsl:copy-of select="@*[not(name()='id')]"/> </input> </xsl:template> + <!-- copy all the rest of the markup which is not recognized above --> <xsl:template match="*"> <xsl:copy><xsl:copy-of select="@*" /><xsl:apply-templates /></xsl:copy> </xsl:template>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]