an example of the use of server-side-transformation of a xsl-transformation using bsf and (object)rexx script 
Author Message
 an example of the use of server-side-transformation of a xsl-transformation using bsf and (object)rexx script

this is an example of the use of server-side-transformation of a xslt
transformation using bsf and (object)rexx script

to use this example you need the following:

a javaversion
a http-server application which a servletengine
a special servlet for the publishing
a (object)rexx version
(a little time to follow the instruction below)

of course you can use other versions or components but you have to spent a
lot of time an implementing it

you should do the following (important to do it step by step and to use the
recommended versions of the programms):
(this installation was made on windows xp and windows 2000)

1. download java jdk1.3.1_03-win.exe from http://www.*-*-*.com/
and install it

2. download jakarta-tomcat-4.0.5.exe from
http://www.*-*-*.com/
install it

3. download cocoon-2.0.3-bin.zip from http://www.*-*-*.com/
unzip it and copy cocoon.war into the apache webapps directory

4. open internetexplorer (it should work with netscape too) and call
http//localhost:8080 after you can see the tomcat starting side call
http://localhost:8080/cocoon after this you scould see the cocoon starting
side

5. close internetexplorer and shut down the tomcat service

6. download megaBSF4Rexx.zip from
http://www.*-*-*.com/
6.a. delete bdf-2.2.jar in the directory webapps\cocoon\WEB-INF\lib
6.b. copy bsf4rexx.jar into webapps\cocoon\WEB-INF\lib and rename it to
bsf-2.2.jar
6.c. look at the instruction for the installing of bsf4rexx to copy the
right bsf*.dll and the bsf.cls and the right definiton of the environment
variable PaTH

7. ad the following code to the sitemap.xmap in the directory webapps\cocoon

<map:match pattern="xsltbsf/**">
  <map:mount check-reload="yes" src="xsltbsf/" uri-prefix="xsltbsf"/>
</map:match>

after the section

<map:match pattern="documents/**">
  <map:mount check-reload="yes" src="documentation/"
uri-prefix="documents"/>
</map:match>

8. make an new directory called xsltbsf in the directory webapps\cocoon

9. ad the following file named sitemap.xmap to the directory
webapps\cocoon\xsltbsf
(sorry for the long code, all of the code except the rexxscript, which is
from mr. rony g. flatscher, is from gerald michalitz) look at point 10 after
the code section

<!-- begin of file  sitemap.xmap -->
<?xml version="1.0"?>
<map:sitemap xmlns:map=" http://www.*-*-*.com/ ;>
 <!-- =========================== Components
================================ -->
 <map:components>
  <map:matchers default="wildcard"/>
  <map:selectors default="browser"/>
  <!-- <map:actions/> -->
  <map:generators default="file" label="content"/>
  <map:transformers default="xslt"/>
  <map:readers default="resource"/>
  <map:serializers default="html"/>
  <map:serializer name="fo2pdf" logger="sitemap.serializer.fo2pdf"
src="org.apache.cocoon.serialization.FOPSerializer"
mime-type="application/pdf"/>
 </map:components>
 <!-- =========================== Pipelines
================================= -->
 <map:pipelines>
  <map:pipeline>
   <map:match pattern="hello-object-rexx.html">
    <map:generate src="hello-page.xml"/>
    <map:transform src="page2html-object-rexx.xsl"/>
    <map:serialize/>
   </map:match>
  </map:pipeline>
  <map:pipeline>
   <map:match pattern="hello-object-rexx.pdf">
    <map:generate src="hello-page.xml"/>
    <map:transform src="page2fo-object-rexx.xsl"/>
    <map:serialize type="fo2pdf"/>
   </map:match>
  </map:pipeline>
 </map:pipelines>
</map:sitemap>
<!-- end of file sitemap.xmap-->

9. ad the following files named hello-page.xml and page2html-object-rexx.xls
and page2fo-object-rexx.xsl to the directory webapps/cocoon/xsltbsf

****************************************************************************
*************
<!-- begin of file hello-page.xml -->

<?xml version="1.0"?>
<!DOCTYPE page [
 <!ELEMENT page (title?, content)>
 <!ELEMENT title (#PCDATA)>
 <!ELEMENT content (para+, deadline)>
 <!ELEMENT para (#PCDATA)>
 <!ELEMENT deadline (#PCDATA)>
 <!ATTLIST deadline
 due_date CDATA #REQUIRED
]>
<?xml-stylesheet type="text/xsl"?>
<page>
 <title>XSL-Transformation of a XML-file to a HTML-file or to a
PDF-file</title>
 <content>
  <para>This is an output of an xsl-transformation of an xml-file to a
html-file or a pdf-file, using bsf (bean scripting framework) and a
Javascript or a (object)rexx script.</para>
  <deadline due_date="June 30, 2002"/>
 </content>
</page>
<!-- end of file hello-page.xml -->
****************************************************************************
*************

****************************************************************************
*************
<!-- begin of file page2html-object-rexx.xls -->

<?xml version="1.0"?>

<xsl:stylesheet
    xmlns:xsl=" http://www.*-*-*.com/ ;
    version="1.0"
    xmlns:lxslt=" http://www.*-*-*.com/ ;
    xmlns:my-ext="ext1"
    extension-element-prefixes="my-ext">

  <xsl:param name="view-source"/>

  <xsl:template match="page">
   <html>
    <head>
     <title>
      <xsl:value-of select="title"/>
     </title>
    </head>
    <body bgcolor="white" alink="red" link="blue" vlink="blue">
     <xsl:apply-templates/>
    </body>
   </html>
  </xsl:template>

  <xsl:template match="title">
   <h2 style="color: navy; text-align: center">
      <xsl:if test="not($view-source)">
         <xsl:apply-templates/>
      </xsl:if>
      <xsl:if test="$view-source">
      <A>
         <xsl:attribute name="HREF">../view-source?filename=/<xsl:value-of
select="$view-source"/></xsl:attribute>
    <xsl:attribute name="TARGET">_blank</xsl:attribute>
         <xsl:apply-templates/>
      </A>
      </xsl:if>
   </h2>
  </xsl:template>

  <xsl:template match="para">
   <p align="left">
    <i><xsl:apply-templates/></i>
   </p>
  </xsl:template>


priority="-2"><xsl:copy><xsl:apply-templates

<!--The component and its script are in the lxslt namespace and define the
    implementation of the extension.-->
    <lxslt:component prefix="my-ext"  functions="calctime">
    <lxslt:script  lang="rexx">
      <![CDATA[
/* calctime rexx - [Object] Rexx, ---rgf, 2002-09-27, wuw */

if arg()=0 then return "(Rexx-calctime: sorry no argument received!)"

parse arg mon +3 . day "," year .          /* parse date             */
due_date    = date("s", day mon year, "n") /* convert to sorted date   */
due_days   = date("b", day mon year, "n")  /* convert argument into # of
days since 0001-01-01 */

today_date = date("s")             /* get today's date in sorted date  */
today_days = date("b", today_date, "s")    /* convert to days since
0001-01-01  */

days=today_days-due_days                   /* calc difference of days
*/
        /* build common return text  */
tmpStr="Received due date=[" || due_date || "], today=[" || today_date
tmpStr=tmpStr || "], hence difference=[" || days || "] days."

     if days<7 then return tmpStr "We tolerate this!"
else if days=7 then return tmpStr "Lucky you, we still tolerate this!"

return tmpStr "Sorry, we can't accept your delay!"
   ]]>

    </lxslt:script>
</lxslt:component>

<xsl:template match="deadline">


</xsl:template>

</xsl:stylesheet>
<!-- end of file page2html-object-rexx.xls -->
****************************************************************************
*************

<!-- begin of file page2fo-object-rexx.xls -->
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
  xmlns:xsl=" http://www.*-*-*.com/ ;
  xmlns:fo=" http://www.*-*-*.com/ ;
  xmlns:lxslt=" http://www.*-*-*.com/ ;
    xmlns:my-ext="ext1"
    extension-element-prefixes="my-ext">

  <xsl:template match="/">
   <fo:root xmlns:fo=" http://www.*-*-*.com/ ;>

    <fo:layout-master-set>
     <fo:simple-page-master master-name="page"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="2cm"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
       <fo:region-before extent="3cm"/>
       <fo:region-body margin-top="3cm"/>
       <fo:region-after extent="1.5cm"/>
     </fo:simple-page-master>

     <fo:page-sequence-master master-name="all">
       <fo:repeatable-page-master-alternatives>
  <fo:conditional-page-master-reference master-reference="page"
page-position="first"/>
       </fo:repeatable-page-master-alternatives>
     </fo:page-sequence-master>
    </fo:layout-master-set>

    <fo:page-sequence master-reference="all">
      <fo:static-content flow-name="xsl-region-after">
 <fo:block text-align="right"
           font-size="10pt"
    font-family="serif"
    line-height="14pt">Page:  <fo:page-number/></fo:block>
      </fo:static-content>

      <fo:flow flow-name="xsl-region-body">
        <xsl:apply-templates/>
      </fo:flow>
    </fo:page-sequence>
   </fo:root>
  </xsl:template>

  <xsl:template match="title">
    <fo:block font-size="36pt" space-before.optimum="24pt"
text-align="center"><xsl:apply-templates/></fo:block>
  </xsl:template>

  <xsl:template match="para">
    <fo:block font-size="12pt" font-color="red" space-before.optimum="12pt"
text-align="center"><xsl:apply-templates/></fo:block>
  </xsl:template>

  <!--The component and its script are in the lxslt namespace and define the
    implementation of the extension.-->
 <lxslt:component prefix="my-ext"  functions="calctime">
    <lxslt:script  lang="rexx">
      <![CDATA[
/* calctime rexx - [Object] Rexx, ---rgf, 2002-09-27, wuw */

if arg()=0 then return "(Rexx-calctime: sorry no argument received!)"

parse arg mon +3 . day "," year .          /* parse date             */
due_date    = date("s", day mon year, "n") /* convert to sorted date   */
due_days   = date("b", day mon year, "n")  /* convert argument into # of
days since 0001-01-01 */

today_date = date("s")             /* get today's date in sorted date  */
today_days = date("b", today_date, "s")    /* convert to days since
0001-01-01  */

days=today_days-due_days                   /* calc difference of days
*/
        /* build common return text  */
tmpStr="Received due date=[" || due_date || "], today=[" || today_date
tmpStr=tmpStr || "], hence difference=[" || days || "] days."

     if days<7 then return tmpStr "We tolerate this!"
else if days=7 then return tmpStr "Lucky you, we still tolerate this!"

return tmpStr "Sorry, we can't accept your delay!"
   ]]>

    </lxslt:script>
</lxslt:component>

  <xsl:template match="deadline">
  <fo:block font-size="12pt" space-before.optimum="12pt"
text-align="center">

  </fo:block>
  </xsl:template>

</xsl:stylesheet>
<!-- end of file page2fo-object-rexx.xls -->

10. start the tomcat service

11. open internetexplorer (it should work with netscape too) and call
http//localhost:8080 after you can see the tomcat starting side call
http://localhost:8080/cocoon after this you scould see the cocoon starting
side, call http://localhost:8080/cocoon/xsltbsf/hello-object-rexx.html after
this you should see the transformed html-file with the result of the
(object)rexx script and if you call
http://localhost:8080/cocoon/xsltbsf/hello-object-rexx.pdf you should see
the transformed pdf-file with the result of the script

sorry for the long explanation and the long codeexample

all of the code, except the (object)rexx-code which is from Mr. Rony G.
Flatscher, is from Gerald Michalitz

if you have any problems on installing the software and the components

greetings

gerald michalitz



Mon, 28 Mar 2005 20:49:02 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Problems with XSL Transformation

2. A problem while trying Xsl transformation with 4Suite

3. Online XML/XSL transformation tool available (based on 4Suite and CherryPy)

4. Transformations for removing side effects?

5. A Question on Matrix Transformation Using J.

6. Server-side Applications - examples wanted

7. Reversible transformation of strings

8. Data Transformation to files: Is RB 1.1 fast enough

9. Transformation and invariant properties.

10. Transformation of algorithms (long)

11. Transformation

12. CfP: LOPSTR'03, Logic-based Program Synthesis and Transformation

 

 
Powered by phpBB® Forum Software