stefano     00/07/21 13:08:22

  Added:       samples/fp README index.xml page-html.xsl
               samples/fp/form default.xml form-html.xsl form-xml.xsl
                        item-add.xml item-edit.xml
               samples/fp/images image1.jpg image2.jpg image3.jpg
  Log:
  added Jeremy's FP
  
  Revision  Changes    Path
  1.1                  xml-cocoon/samples/fp/README
  
  Index: README
  ===================================================================
  I'll walk you through the "Add Item" example.
  Sorry, this is really rough.
  
  
  It's XML.
  
        <?xml version="1.0"?>
  
  You want it processed as XSP, then XSLT.
  
        <?cocoon-process type="xsp"?>
        <?cocoon-process type="xslt"?>
  
  This is your StyleSheet.
  
        <?xml-stylesheet type="text/xsl" href="form-html.xsl"?>
        
  If you change this reference to "form-xml.xsl" you can see the output of the 
TagSet before it goes to the StyleSheet.
  
  Declare the xsp:page and the Tag Libraries we are using, including the FP 
TagLib.
  
        <xsp:page 
                xmlns:fp="http://apache.org/cocoon/XSP/FP/1.0";
                xmlns:request="http://www.apache.org/1999/XSP/Request";
                xmlns:util="http://www.apache.org/1999/XSP/Util";
                xmlns:xsp="http://www.apache.org/1999/XSP/Core";
                language="java"
        >
  
  Declare your "user" root element, any name will do    
  
        <page>
        
  The fp:resource tag declares an external file that you can read and write to.
  The "id" attribute is the name you will refer to it by.
  This is the file we are going to get default values for the form from.
  
                <fp:resource id="default-item">
                
  The path to the file
  
                        <fp:resource-file>default.xml</fp:resource-file>
                        
  The root node you want to work from, specified as an XPath.
  
                        <fp:resource-node>form/page/item</fp:resource-node>
                        
  Close the resource
  
                </fp:resource>
                
  This is the file we are going to modify.
  
                <fp:resource id="external-item">
                
                        <fp:resource-file>../index.xml</fp:resource-file>
                        
  We are nesting a Tag from the Request TagLib inside an FP Tag to build an 
XPath on the fly from the "item" request parameter.
  
                        
<fp:resource-node>item[position()=<request:get-parameter 
name="item"/>]</fp:resource-node>
                        
  We are writing to the resource, this inserts a new "item" Node before the 
current one, to be filled by the Form data.
  
                        <fp:default-mode>insert-before</fp:default-mode>
                </fp:resource>
  
  You can pass along anything you want in this file             
  
                <title>Add more News</title>
                
  Use other TagLibs
  
                <method><request:get-method/></method>
                <task>add</task>
                
  Here, I want to get the Title of all onf the Items, to build a Menu.
  
                <menu action="item-add.xml?item=">
                
  The fp:read Tag is replaced by the contents of the read.
  The "from" Attribute is the name of the resource you want to read.
  The "select" Attribute is an XPath relative to the Node specified in this 
resource's "resource-node".
  The "as" Attribute, in this case "node" specified that the data should be 
read and passed on as XML.
  Status and Error id's are added as attributes to the parent of the fp:read 
tag, in this case the <menu/> tag.
  
                        <fp:read select="../item/title" from="external-item" 
as="node"/>
                </menu>
  
  The output looks like this:
  <menu fp-action="read" [fp-error="fp-1"] fp-from="external-item" 
fp-select="../item/title" fp-type="text/xml">
        <title>Title 1</title>
        <title>Title 2</title>
        <title>Title ...</title>
  </menu>
  If there is an error, you get the ID of the error report, placed at the end 
of the page.
  
  It's a Form, could be anything
  
                <form action="item-add.xml" method="POST">
                
  It's a Form Field, so the name is important, but it does not need to relate 
to the name of the location where the data is to be stored.
  
                        <input name="title">
                        
  I create a "label" Attribute in the "input" Element, using XSP, but the 
content comes from reading Text from the defaults file. (as="string" is the 
default for read and write).
  
                                <xsp:attribute name="label"><fp:read 
select="title/label" from="default-item"/></xsp:attribute>
                                
  Only do this bit if someone is POSTing a Form.
  
                                <fp:if-post>
                                
  Write the contents of the fp:write Tag, in this case the value of the POSTed 
Form field called "title" (this one), to the Title Node of the external file, 
as Text.
  The fp:write Tag does not emit anything into the <input/> tag, except status 
Attributes. 
  
                                        <fp:write to="external-item" 
select="title">
                                                <request:get-parameter 
name="title"/>
                                        </fp:write>
                                        
  This reads the info back out, it ends up being the contents of the <input/> 
tag.
  
                                        <fp:read select="title" 
from="external-item"/>
                                </fp:if-post>
                                
  Only do this bit if someone is GETting a Form.
  
                                <fp:if-get>
                                
  Get the default value for the field.
  
                                        <fp:read select="title/value" 
from="default-item"/>
                                </fp:if-get>
                        </input>
                        
  A TEXTAREA to put the Body text in as a Node, so we can edit and retain it as 
XML, otherwise does the same as the previous field.
  
                        <input name="body" type="textarea">
                                <xsp:attribute name="label"><fp:read 
select="body/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write select="body" 
to="external-item" as="node">
                                                <request:get-parameter 
name="body"/>
                                        </fp:write>
                                        <fp:read select="body" 
from="external-item" as="node"/>
                                </fp:if-post>
                                <fp:if-get>
                                        <fp:read select="body/value/body" 
from="default-item" as="node"/>
                                </fp:if-get>
                        </input>
                        
  A SELECT, to choose the Image.
  
                        <input name="figure" type="select">
                        
  Get the label as usual
  
                                <xsp:attribute name="label"><fp:read 
select="figure/label" from="default-item"/></xsp:attribute>
                                
  Always get all of the select option values from the defaults file.
  
                                <fp:read as="node" select="figure/value" 
from="default-item"/>
                                
  If POST, write the value to the external file
  
                                <fp:if-post>
                                        <fp:write select="figure" 
to="external-item">
                                                <request:get-parameter 
name="figure"/>
                                        </fp:write>
                                        
  Read the current selection, put it in a <selection/> Element
  
                                        <selection><fp:read select="figure" 
from="external-item"/></selection>
                                </fp:if-post>
                        </input>
                        
  A hidden field, to pass on our "item" parameter
  
                        <input name="item" type="hidden">
                                <value><request:get-parameter 
name="item"/></value>
                        </input>
                        
  Write a date on save
  
                        <input name="date">
                                <fp:if-post>
                                
  I can't remember why I snuck the fp:redirect in here, it could go anywhere.
  
                                        <fp:redirect>../index.xml</fp:redirect>
                                        <fp:write select="date" 
to="external-item">
                                                <util:time format="dd/MM/yyyy 
hh:mm:ss"/>
                                        </fp:write>
                                </fp:if-post>
                        </input>
                        
  Make a Submit button from the defaults.
  
                        <input name="submit" type="submit">
                                <xsp:attribute name="label"><fp:read 
select="submit/label" from="default-item"/></xsp:attribute>
                                <fp:read select="submit/value" 
from="default-item"/>
                        </input>
                </form>
        </page>
  </xsp:page>
  
  That's for now I'm afraid :(
  
  BTW.
  
  You can put an fp:read inside an fp:write to move or copy data from one file 
or Node to another.
  An fp:read inside an fp:write, will not send it's contents to the parent of 
the fp:write.
  
  
  
  1.1                  xml-cocoon/samples/fp/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  <?cocoon-process type="xslt"?>
  <?xml-stylesheet href="page-html.xsl" type="text/xsl"?>
  <page>  
    <title>FP Demo</title>
    <author>
      <name>Jeremy Quinn</name>
      <address>[EMAIL PROTECTED]</address>
    </author>
  
    <item>
      <title>FP TagLib</title>
      <body>
        <p>This is a demo of the FP Taglib.</p>
        
        <p>There is a completely normal XML Data page <a 
href="../xsp/view-source.xml?filename=../fp/index.xml" 
target="blank">index.xml</a>, 
         viewed with the StyleSheet <a 
href="../xsp/view-source.xml?filename=../fp/page-html.xsl" 
target="blank">page-html.xsl</a>, 
         containing multiple &lt;item/&gt; Nodes, that can be individually 
edited. This is this functionality that the FP TagSet brings.</p>
        
        <p>Click on the [edit] link above to edit this Item, click on the [add] 
link to add a new Item, before this one.</p>
        
        <p>There is an XML File using the FP TagLib that provides for editing, 
called 
         <a href="../xsp/view-source.xml?filename=../fp/form/item-edit.xml" 
target="blank">form/item-edit.xml</a>
         and another called <a 
href="../xsp/view-source.xml?filename=../fp/form/item-add.xml" 
target="blank">form/item-add.xml</a>
         for adding. They are both viewed using this StyleSheet <a 
href="../xsp/view-source.xml?filename=../fp/form/form-html.xsl" 
target="blank">form/form-html.xsl</a>.</p>
      </body>
  
      <figure>images/image1.jpg</figure>
      <date>12/07/2000 04:35:45</date>
    </item>
    
    <item>
      <title>Another Item</title>
      <body>This field for instance, is handled as XML. If you write bad XML 
into it and try to save, you should get a parser error.</body>
      <figure>images/image2.jpg</figure>
      <date>12/07/2000 12:31:48</date>
    </item>
    
    
        
        <item>
        <title>Novit� di Stefano</title>
        <body>Mitico!!!</body>
        <figure>images/image1.jpg</figure>
        <date>21/07/2000 10:00:26</date></item><item>
        <title>Your News Item Title</title>
        <body>Your Body Text</body>
        <figure>images/image1.jpg</figure>
        <date>21/07/2000 09:59:54</date></item><item>
      <title>Lorem ipsum</title>
      <body>
  <p>Stefano dice <strong>ciao</strong></p>
        <p>Lorem ipsum dolor sit <em>amet</em>, consectetuer adipiscing elit, 
        sed diam nonummy nibheuis erat volutpat. Ut wisi enim ad minim veniam, 
        quis nostrud exerci tation ullamcorper suscipit lobortis nisul ut 
aliquip 
        ex ea commodo.</p>
        <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse 
        molestie consequat, vel blandit praesent lupatum zril delenit augue 
duis 
        dolore te feugait nulla.</p>
        <p>Exerci tation ullamcorper suscipit lobortis nisl feugiat nulla 
        facilisis at vero eros et accumsan et iusto odio dignissim quiblandit 
        prasent.</p>
      </body>
      <date>21/07/2000 09:59:40</date>
      <figure>images/image2.jpg</figure>
    </item>  
  </page>
  
  
  
  1.1                  xml-cocoon/samples/fp/page-html.xsl
  
  Index: page-html.xsl
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  <xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
        <xsl:template match="page">
                <xsl:processing-instruction 
name="cocoon-format">type="text/html"</xsl:processing-instruction>
                <html>
                        <head>
                                <title><xsl:value-of select="title"/></title>
                                <meta name="author">
                                <xsl:attribute name="content"><xsl:value-of 
select="author/name"/> - <xsl:value-of select="author/address"/></xsl:attribute>
                        </meta>
                        <style type="text/css"><![CDATA[
                                .menutext 
{font-family:Verdana;font-size:10px;color:white;font-weight:normal}
                                .menutitle 
{font-family:Verdana;font-size:28px;color:white;font-weight:bold}
                                        .bodytext 
{font-family:Verdana;font-size:12px;color:black}
                                        .date 
{font-family:Verdana;font-size:9px;color:black}
                                        .commandtext 
{font-family:Verdana;font-size:9px}
                                        .bodytitle 
{font-family:Verdana;font-size:18px;color:black;font-weight:bold}
                                        a {text-decoration: none}
                                        a:link {color: orange}
                                        a:visited {color: orange}
                                        a:active {color: red}
                                        a:hover {text-decoration: underline; 
color: red}
                                        .menutext a:link {color: white}
                                        .menutext a:visited {color: white}
                        ]]></style>
                        </head>
                        <body bgcolor="white"><center>
                                <table cellspacing="0" cellpadding="5" 
width="580" border="0">
                                        <tr valign="top">
                                                <td bgcolor="#006699" 
class="menutext" width="180">
                                                        <p 
class="menutitle"><xsl:value-of select="title"/></p>
                                                        <xsl:for-each 
select="item">
                                                                <p 
class="menutext">
                                                                        <a>
                                                                                
<xsl:attribute name="href">#<xsl:value-of select="position()"/></xsl:attribute>
                                                                                
<xsl:value-of select="title"/>
                                                                        </a>
                                                                </p>
                                                        </xsl:for-each>
                                                </td>
                                                <td>
                                                        <xsl:apply-templates 
select="item"/>
                                                </td>
                                        </tr>
                                        <tr valign="bottom">
                                                <td bgcolor="#006699" 
class="date">
                                                        <xsl:value-of 
select="author/name"/><br/>
                                                        <xsl:value-of 
select="author/address"/>
                                                </td>
                                        </tr>
                                </table>
                        </center></body>
                </html>
        </xsl:template>
        
        <xsl:template match="item">
                <a>
                        <xsl:attribute name="name"><xsl:value-of 
select="position()"/></xsl:attribute>
                        <table cellspacing="0" cellpadding="5" width="100%" 
border="0">
                                <tr valign="top">
                                        <td class="bodytitle">
                                                <xsl:value-of select="title"/>
                                        </td>
                                        <td rowspan="3" align="right">
                                                <xsl:apply-templates 
select="figure"/>
                                        </td>
                                </tr>
                                <tr valign="top">
                                        <td class="date">
                                                <xsl:value-of select="date"/>
                                        </td>
                                </tr>
                                <tr valign="top">
                                        <td class="commandtext">
                                                <a>
                                                        <xsl:attribute 
name="href">form/item-edit.xml?item=<xsl:value-of 
select="position()"/></xsl:attribute>
                                                        
<xsl:text>[edit]</xsl:text>
                                                </a>
                                                <a>
                                                        <xsl:attribute 
name="href">form/item-add.xml?item=<xsl:value-of 
select="position()"/></xsl:attribute>
                                                        
<xsl:text>[add]</xsl:text>
                                                </a>
                                        </td>
                                </tr>
                                <tr valign="top">
                                        <td colspan="2" class="bodytext">
                                                <xsl:apply-templates 
select="body"/>
                                        </td>
                                </tr>
                        </table>
                </a><hr/>
        </xsl:template>
        
        <xsl:template match="figure">
                <xsl:if test=".!=''">
                        <img width="64" height="64" border="1">
                                <xsl:attribute name="src"><xsl:value-of 
select="."/></xsl:attribute>
                        </img>
                </xsl:if>
        </xsl:template>
  
        <xsl:template match="body">
                <xsl:copy>
                        <xsl:apply-templates select="*|@*|text()"/>
                </xsl:copy>
        </xsl:template>
  
        <xsl:template match="*|@*|text()">
                <xsl:copy>
                        <xsl:apply-templates select="*|@*|text()"/>
                </xsl:copy>
        </xsl:template>
        
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon/samples/fp/form/default.xml
  
  Index: default.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  
  <defaults>
    <form>
      <page>
        <title>The Title</title>
        <author>
         <name>Author's Name</name>
         <address>Author's Email Address</address>
        </author>
        <item>
          <title>
            <label>Title</label>
            <value>Your News Item Title</value>
          </title>
          <body>
            <label>Body Text</label>
            <value>
             <body>Your Body Text</body>
            </value>
          </body>
          <figure>
            <label>image</label>
            <value>
              <option value="images/image1.jpg">One</option>
              <option value="images/image2.jpg">Two</option>
              <option value="images/image3.jpg">Three</option>
            </value>
          </figure>
          <submit>
            <label>Finished?</label>
            <value>Save it</value>
          </submit>
        </item>
      </page>
    </form>
  </defaults>
  
  
  
  1.1                  xml-cocoon/samples/fp/form/form-html.xsl
  
  Index: form-html.xsl
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  
  <xsl:stylesheet 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        xmlns:fp="http://apache.org/cocoon/XSP/FP/1.0";
        version="1.0">
  
  <xsl:template match="/">
        <HTML>
                <HEAD>
                        <TITLE>FP TagLib Example</TITLE>
                        <STYLE TYPE="text/css"><![CDATA[
                                td 
{font-family:Verdana;font-size:10px;color:black;font-weight:bold}
                        .menu {font-weight:normal}
                        .title {font-size:20px}
                        .processes {font-size:9px;font-weight:normal}
                        .process {color:green}
                        .error {font-size:9px;font-weight:bold; color:red}
                        .errors {font-size:9px;font-weight:normal}
                        ]]></STYLE>
                </HEAD>
                <BODY BGCOLOR="#FFFFFF">
                        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="10">
                                <TR VALIGN="TOP">
                                        <TD>
                                                <xsl:apply-templates 
select="*/menu"/>
                                        </TD><TD>
                                                <xsl:apply-templates 
select="*/title"/>
                                                <xsl:apply-templates 
select="*/date"/>
                                                <xsl:apply-templates 
select="*/method"/>
                                                <xsl:apply-templates 
select="*/task"/>
                                                <xsl:apply-templates 
select="*/form"/>
                                        </TD>
                                </TR>
                        </TABLE>
                </BODY>
        </HTML>
  </xsl:template>
  
  <xsl:template match="form">
        <FORM METHOD="POST">
                <xsl:for-each select="@*">
                        <xsl:copy/>
                </xsl:for-each>
                <TABLE BORDER="0" CELLPADDING="4" CELLSPACING="10">
                        <xsl:apply-templates/>
                </TABLE>
        </FORM>
  </xsl:template>
  
  <xsl:template match="[EMAIL PROTECTED]'checkbox']">
        <TR BGCOLOR="#CCCCCC" VALIGN="TOP">
                <TD></TD>
                <TD>
                        <INPUT>
                                <xsl:call-template name="copy-form-attributes"/>
                        </INPUT>
                        <xsl:value-of select="@value"/>
                </TD>
                <xsl:call-template name="show-processes"/>
                <xsl:call-template name="show-errors"/>
        </TR>
  </xsl:template>
  
  <xsl:template match="[EMAIL PROTECTED]'hidden']">
        <INPUT>
                <xsl:call-template name="copy-form-attributes"/>
                <xsl:for-each select="*">
                        <xsl:attribute name="{name(.)}"><xsl:value-of 
select="normalize-space(.)"/></xsl:attribute>
                </xsl:for-each>
        </INPUT>
  </xsl:template>
  
  <xsl:template match="[EMAIL PROTECTED]'select']">
        <xsl:variable name="selection"><xsl:value-of 
select="selection"/></xsl:variable>
        <TR BGCOLOR="#CCCCCC" VALIGN="TOP">
                <TD ALIGN="RIGHT"><xsl:value-of select="@label"/></TD>
                <TD>
                        <SELECT>
                                <xsl:call-template name="copy-form-attributes"/>
                                <xsl:for-each select="value/option">
                                        <xsl:copy>
                                                <xsl:apply-templates 
select="@*"/>
                                                <xsl:if test="@value = 
$selection">
                                                        <xsl:attribute 
name="selected">selected</xsl:attribute>
                                                </xsl:if>
                                                <xsl:apply-templates/>
                                        </xsl:copy>
                                </xsl:for-each>
                                <xsl:for-each select="value/*">
                                        <xsl:copy-of select="option"/>
                                </xsl:for-each>
                        </SELECT>
                </TD>
                <xsl:call-template name="show-processes"/>
                <xsl:call-template name="show-errors"/>
        </TR>
  </xsl:template>
  
  <xsl:template match="[EMAIL PROTECTED]'textarea']">
        <xsl:variable name="value">
                <xsl:call-template name="get-nested-content">
                        <xsl:with-param name="content" select="."/>
                </xsl:call-template>
        </xsl:variable>
        <TR BGCOLOR="#CCCCCC" VALIGN="TOP">
                <TD ALIGN="RIGHT"><xsl:value-of select="@label"/></TD>
                <TD>
                        <TEXTAREA ROWS="10" COLS="40"><xsl:call-template 
name="copy-form-attributes"/><xsl:copy-of select="$value"/></TEXTAREA>
                </TD>
                <xsl:call-template name="show-processes"/>
                <xsl:call-template name="show-errors"/>
        </TR>
  </xsl:template>
  
  <xsl:template match="input">
        <xsl:variable name="value">
                <xsl:call-template name="get-nested-content">
                        <xsl:with-param name="content" select="."/>
                </xsl:call-template>
        </xsl:variable>
        <xsl:if test="$value">
                <TR BGCOLOR="#CCCCCC" VALIGN="TOP">
                        <TD ALIGN="RIGHT"><xsl:value-of select="@label"/></TD>
                        <TD>
                                <INPUT>
                                        <xsl:call-template 
name="copy-form-attributes"/>
                                        <xsl:attribute 
name="value"><xsl:value-of select="normalize-space($value)"/></xsl:attribute>
                                </INPUT>
                        </TD>
                        <xsl:call-template name="show-processes"/>
                        <xsl:call-template name="show-errors"/>
                </TR>
        </xsl:if>
  </xsl:template>
  
  <xsl:template name="copy-form-attributes">
        <xsl:for-each select="@*[substring(name(), 1, 3) != 'fp-']">
                <xsl:copy/>
        </xsl:for-each>
  </xsl:template>
  
  <xsl:template name="show-processes">
        <TD CLASS="processes">
                <xsl:for-each select="@*[substring(name(), 1, 3) = 'fp-']">
                        <xsl:value-of select="name(.)"/>: <span 
class="process"><xsl:value-of select="."/></span><br/>
                </xsl:for-each>
        </TD>
  </xsl:template>
  
  <xsl:template name="show-errors">
        <xsl:variable name="code"><xsl:value-of 
select="@fp-error"/></xsl:variable>
        <TD CLASS="errors">
                <xsl:if test="$code!=''">
                        <xsl:for-each select="/*/[EMAIL PROTECTED]/*">
                        <xsl:value-of select="name(.)"/>: <span 
class="error"><xsl:value-of select="."/></span><br/>
                        </xsl:for-each>
                </xsl:if>
        </TD>
  </xsl:template>
  
  <xsl:template match="menu">
        <xsl:variable name="action"><xsl:value-of 
select="@action"/></xsl:variable>
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="2">
                <xsl:for-each select="title">
                        <TR>
                                <TD CLASS="menu">
                                        <xsl:element name="a">
                                                <xsl:attribute 
name="href"><xsl:value-of select="$action"/><xsl:value-of 
select="position(.)"/></xsl:attribute>
                                                <xsl:value-of select="."/>
                                        </xsl:element>
                                </TD>
                        </TR>
                </xsl:for-each>
        </TABLE>
  </xsl:template>
  
  <xsl:template match="title">
        <span class="title"><xsl:value-of select="."/></span><br/>
  </xsl:template>
  
  <xsl:template match="method">
        Method: <xsl:value-of select="."/><br/>
  </xsl:template>
  
  <xsl:template match="date">
        Last Modified: <xsl:value-of select="."/><br/>
  </xsl:template>
  
  <xsl:template match="task">
        Task: <xsl:value-of select="."/><br/>
        Item:  <xsl:value-of select="//[EMAIL PROTECTED]'item']"/><br/>
        Errors:  <xsl:value-of select="../@fp-errors"/><br/><br/><br/>
  </xsl:template>
  
  <xsl:template name="get-nested-content">
        <xsl:param name="content"/>
        <xsl:choose>
                <xsl:when test="$content/*">
                        <xsl:apply-templates select="$content/*"/>
                </xsl:when>
                <xsl:otherwise><xsl:value-of select="$content"/></xsl:otherwise>
        </xsl:choose>
  </xsl:template>
  
  <xsl:template match="@*|node()" priority="-1">
        <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon/samples/fp/form/form-xml.xsl
  
  Index: form-xml.xsl
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  
  <xsl:stylesheet 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        xmlns:fp="http://apache.org/cocoon/XSP/FP/1.0";
        version="1.0">
  
        <xsl:template match="/">
                <xsl:processing-instruction 
name="cocoon-format">type="text/xml"</xsl:processing-instruction>
                
                <xsl:apply-templates/>
        </xsl:template>
  
        <xsl:template match="*|@*|text()">
                <xsl:copy>
                        <xsl:apply-templates select="*|@*|text()"/>
                </xsl:copy>
        </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon/samples/fp/form/item-add.xml
  
  Index: item-add.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  
  <?cocoon-process type="xsp"?>
  <?cocoon-process type="xslt"?>
  
  <?xml-stylesheet type="text/xsl" href="form-html.xsl"?>
  
  <xsp:page 
        xmlns:fp="http://apache.org/cocoon/XSP/FP/1.0";
        xmlns:request="http://www.apache.org/1999/XSP/Request";
        xmlns:util="http://www.apache.org/1999/XSP/Util";
        xmlns:xsp="http://www.apache.org/1999/XSP/Core";
        language="java"
  >
        
        <page>
                <fp:resource id="default-item">
                        <fp:resource-file>default.xml</fp:resource-file>
                        <fp:resource-node>form/page/item</fp:resource-node>
                </fp:resource>
                <fp:resource id="external-item">
                        <fp:resource-file>../index.xml</fp:resource-file>
                        
<fp:resource-node>item[position()=<request:get-parameter 
name="item"/>]</fp:resource-node>
                        <fp:default-mode>insert-before</fp:default-mode>
                </fp:resource>
                
                <title>Add more News</title>
                <method><request:get-method/></method>
                <task>add</task>
                <menu action="item-add.xml?item=">
                        <fp:read select="../item/title" from="external-item" 
as="node"/>
                </menu>
  
                
                <form action="item-add.xml" method="POST">
                        <input name="title">
                                <xsp:attribute name="label"><fp:read 
select="title/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write to="external-item" 
select="title">
                                                <request:get-parameter 
name="title"/>
                                        </fp:write>
                                        <fp:read select="title" 
from="external-item"/>
                                </fp:if-post>
                                <fp:if-get>
                                        <fp:read select="title/value" 
from="default-item"/>
                                </fp:if-get>
                        </input>
                        <input name="body" type="textarea">
                                <xsp:attribute name="label"><fp:read 
select="body/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write select="body" 
to="external-item" as="node">
                                                <request:get-parameter 
name="body"/>
                                        </fp:write>
                                        <fp:read select="body" 
from="external-item" as="node"/>
                                </fp:if-post>
                                <fp:if-get>
                                        <fp:read select="body/value/body" 
from="default-item" as="node"/>
                                </fp:if-get>
                        </input>
                        <input name="figure" type="select">
                                <xsp:attribute name="label"><fp:read 
select="figure/label" from="default-item"/></xsp:attribute>
                                <fp:read as="node" select="figure/value" 
from="default-item"/>
                                <fp:if-post>
                                        <fp:write select="figure" 
to="external-item">
                                                <request:get-parameter 
name="figure"/>
                                        </fp:write>
                                        <selection><fp:read select="figure" 
from="external-item"/></selection>
                                </fp:if-post>
                        </input>
                        <input name="item" type="hidden">
                                <value><request:get-parameter 
name="item"/></value>
                        </input>
                        <input name="date">
                                <fp:if-post>
                                        <fp:redirect>../index.xml</fp:redirect>
                                        <fp:write select="date" 
to="external-item">
                                                <util:time format="dd/MM/yyyy 
hh:mm:ss"/>
                                        </fp:write>
                                </fp:if-post>
                        </input>
                        <input name="submit" type="submit">
                                <xsp:attribute name="label"><fp:read 
select="submit/label" from="default-item"/></xsp:attribute>
                                <fp:read select="submit/value" 
from="default-item"/>
                        </input>
                </form>
        </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon/samples/fp/form/item-edit.xml
  
  Index: item-edit.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- Written by Jeremy Quinn "[EMAIL PROTECTED]" -->
  
  <?cocoon-process type="xsp"?>
  <?cocoon-process type="xslt"?>
  
  <?xml-stylesheet type="text/xsl" href="form-html.xsl"?>
  
  <xsp:page
        xmlns:fp="http://apache.org/cocoon/XSP/FP/1.0";
        xmlns:request="http://www.apache.org/1999/XSP/Request";
        xmlns:util="http://www.apache.org/1999/XSP/Util";
        xmlns:xsp="http://www.apache.org/1999/XSP/Core";
        language="java" 
  >
        <page>
                <fp:resource id="default-item">
                        <fp:resource-file>default.xml</fp:resource-file>
                        <fp:resource-node>form/page/item</fp:resource-node>
                </fp:resource>
                <fp:resource id="external-item">
                        <fp:resource-file>../index.xml</fp:resource-file>
                        
<fp:resource-node>item[position()=<request:get-parameter 
name="item"/>]</fp:resource-node>
                        <fp:default-mode>replace</fp:default-mode>
                </fp:resource>
                
                <title>Edit the Page</title>
                <method><request:get-method/></method>
                <task>edit</task>
                <date><fp:read select="date" from="external-item"/></date>
                <menu action="item-edit.xml?item=">
                        <fp:read select="../item/title" from="external-item" 
as="node"/>
                </menu>
                
                <form action="item-edit.xml" method="POST">
                        <input name="title">
                                <xsp:attribute name="label"><fp:read 
select="title/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write to="external-item" 
select="title">
                                                <request:get-parameter 
name="title"/>
                                        </fp:write>
                                </fp:if-post>
                                <fp:read select="title" from="external-item"/>
                        </input>
                        <input name="body" type="textarea">
                                <xsp:attribute name="label"><fp:read 
select="body/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write select="body" 
to="external-item" as="node">
                                                <request:get-parameter 
name="body"/>
                                        </fp:write>
                                </fp:if-post>
                                <fp:read select="body" from="external-item" 
as="node"/>
                        </input>
                        <input name="figure" type="select">
                                <xsp:attribute name="label"><fp:read 
select="figure/label" from="default-item"/></xsp:attribute>
                                <fp:if-post>
                                        <fp:write select="figure" 
to="external-item">
                                                <request:get-parameter 
name="figure"/>
                                        </fp:write>
                                </fp:if-post>
                                <selection><fp:read select="figure" 
from="external-item"/></selection>
                                <fp:read as="node" select="figure/value" 
from="default-item"/>
                        </input>
                        <input name="date">
                                <fp:if-post>
                                        <fp:redirect>../index.xml</fp:redirect>
                                        <fp:write select="date" 
to="external-item">
                                                <util:time format="dd/MM/yyyy 
hh:mm:ss"/>
                                        </fp:write>
                                </fp:if-post>
                        </input>
                        <input name="item" type="hidden">
                                <value><request:get-parameter 
name="item"/></value>
                        </input>
                        <input name="submit" type="submit">
                                <xsp:attribute name="label"><fp:read 
select="submit/label" from="default-item"/></xsp:attribute>
                                <fp:read select="submit/value" 
from="default-item"/>
                        </input>
                </form>
        </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon/samples/fp/images/image1.jpg
  
        <<Binary file>>
  
  
  1.1                  xml-cocoon/samples/fp/images/image2.jpg
  
        <<Binary file>>
  
  
  1.1                  xml-cocoon/samples/fp/images/image3.jpg
  
        <<Binary file>>
  
  

Reply via email to