1. Cocoon Introduction According to the official definition of Apache, cocoon is an XML release framework. It allows you to define the conversion of XML documents and documents, and eventually generate the representations you choose, such as HTML, PDF, SVG, VRML, and more. In addition, Cocoon enables you to add processing logic in the XML file, thus a dynamic characteristic of the XML pipe.
2, download and installation
Download the latest version of Cocoon from http://xml.apache.org/, this article is in an example of version 2.1.6. Unzip the deployment package to the application server, this article takes Tomcat as an example. Visit http: // loclahost: 8080 / cocoon / See if the welcome interface appears.
3, Hello, Cocoon
After the CoCoon installation configuration is complete, you can run the routines provided by the system, or you can make an XSP program yourself. This article provides a simple program for reference. 3.1 File Description Program Name: Hello.xsp Conversion File: Hello.xsl3.2 File List 3.2.1 Hello.xsp
XML Version = "1.0" encoding = "ISO-8859-1"> cocoon-process type = "XSP"?> Expand the page of XSP ->
tag defines business logic ->
3.2.2
Hello.xsl
XML Version = "1.0" encoding = "ISO-8859-1"?>
The value in the mark is output ->
The XSL style list can convert the XML document and output the specified style. 3.3 The configuration before the release first can be placed in the {Tomcat_Home} / WebApps / Cocoon / Hello directory. Thereafter, the corresponding configuration is required in SiteMap.xMap. Add to
map: match>
According to the above configuration, the style is specified in the style of hello / hello.xsl, and as long as you enter http: // localhost: 8080 / cocoon / hello / hello in the URL, send the result to In the browser. Similarly, if there is Hello2.xsp in this directory, you can call via http: // localhost: 8080 / cocoon / hello / hello2. It should be noted that after modifying SiteMap.xmap, you need to restart Tomcat or resin to make the modification take effect, otherwise you can try the check-reload attribute in the SiteMap mark in the Cocoon.xConf file, for example:
4, from XML to HTML and PDF
4.1, Creating an XML Sample Document We use a simple XML file as a data source. You may use the actual XML or database or the like as a data source. Test.xml content: XML Version = "1.0" eNCoding = "ISO-8859-1"> this is the text of section one p> s1> page> 4.2, creating XSLT to generate HTML in Cocoon is used to generate HTML in Cocoon is to select and convert input documents using XSLT Suitable elements. Copy the DOC2HTML.XSL below to the HTML-PDF directory to make it together with the above two XML documents. DOC2HTML.XSL content: XML Version = "1.0" encoding = "ISO-8859-1"> map: Components> map: Sitemap> The above file is a very important thing is that