home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / ctwig-basic02.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  3.6 KB  |  67 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
  18.  
  19. <document>
  20.     <header>
  21.         <title>cTwIG - Cocoon Two Idiots Guide - Basic XSP Processing</title>
  22.         <authors>
  23.             <person name="Jeremy Aston" email="jez@pigbite.com"/>
  24.         </authors>
  25.     </header>
  26.  
  27.     <body>
  28.         <s1 title="Transformations">
  29.             <s2 title="Basic XSP Processing">
  30.                 <p>XSP allows you to incorporate logic into the XML file thus providing capabilities analogous to ASP, JSP, CFM, PHP etc.  The advantage is that the logic is not tied to the rendering since a stylesheet is separately applied.  The results of the code are wrapped up in a tag which is what can be referenced in the stylesheet.</p>
  31.                 <p>Take the following XML file (<fork href="sample/transformations/basic02/basic02-01.xml">basic02-01.xml</fork>):</p>
  32.                 <source><![CDATA[
  33.   <?xml version="1.0"?>
  34.   <xsp:page 
  35.       xmlns:xsp="http://apache.org/xsp"
  36.   >
  37.  
  38.     <page>
  39.       <xsp:logic>
  40.         String msg = "Hello world!";
  41.       </xsp:logic>
  42.  
  43.       <title>
  44.         Basic XSP Processing Example - BASIC02-01.XML
  45.         </title>
  46.  
  47.       <greeting>
  48.         <xsp:expr>msg</xsp:expr>
  49.       </greeting>
  50.     </page>
  51.   </xsp:page>]]></source>
  52.                 <p>We have now wrapped the previous file up with an xsp:page tag and added some logic that assigns "Hello World" to a string and uses the xsp:expr tag to insert that in place of the previous text in the greeting tag.   <em>Please note that this example uses "http://apache.org/xsp" as the namespace.  This is different to older C1 based examples and should be used instead.  If you do not then this examples may not work and any logicsheet example definitely will not work.</em></p>
  53.                 <p>To render this we need to tell Cocoon that this file is an XSP file.  This is easier if we either name the file as .xsp and/or put it in an XSP folder.  For now just put it in {TOMCAT_HOME}\webapps\cocoon\ctwig\xsp, keeping the .xml extension.  You can now add the following to the sitemap.xmap file:</p>
  54.                 <source><![CDATA[
  55.   <map:match pattern="ctwig/xsp/*"> 
  56.     <map:generate type="serverpages" src="ctwig/xsp/{1}"/> 
  57.     <map:transform type="xslt" src="ctwig/basic01-01.xsl"/> 
  58.     <map:serialize/> 
  59.   </map:match>]]></source>
  60.                 <p>What this does is to force any file in the ctwig/xsp folder to be processed using the "serverpages" (XSP) generator, then rendered with the same XSL stylesheet as in the Basic01 example.  Note that we are telling C2 that the stylesheet is in the ctwig folder.</p>
  61.                 <p>You can test this code by calling <fork href="http://localhost:8080/cocoon/ctwig/xsp/basic02-01.xml">http://localhost:8080/cocoon/ctwig/xsp/basic02-01.xml</fork></p>
  62.                 <p>The one downside with this approach is that you can end up with XML files that contain lots of logic along with the rest of the data.  This becomes as confusing to read as when the logic is mixed with the presentation so does not really solve all the issues that are inherent to the ASP/JSP type approach.  The solution is to use <link href="ctwig-basic03.html">logicsheets</link>.</p>
  63.             </s2>
  64.         </s1>
  65.     </body>
  66. </document>
  67.