shannon 2002/06/19 13:15:06
Added: src/documentation/xdocs/snippet snippet-xslt-options.xml
Log:
New snippet which shows how
to configure XSLT processor
components to handle multiple
processing options. Written
with feedback from Vadim.
Revision Changes Path
1.1
xml-cocoon2/src/documentation/xdocs/snippet/snippet-xslt-options.xml
Index: snippet-xslt-options.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN"
"../dtd/document-v10.dtd">
<document>
<header>
<title>Specifying Different XSLT Processor Options</title>
<authors>
<person name="Vadim Gritsenko" email="[EMAIL PROTECTED]"/>
<person name="Diana Shannon" email="[EMAIL PROTECTED]"/>
</authors>
</header>
<body>
<s1 title="Overview">
<p>
This Snippet shows how to specify different options of the same XSLT
processor when processing different pipeline requests. The following example is
based on the need to turn incremental processing both off and on. This is
useful in situations when processing requests for both PDF and HTML output. For
example, you may want to turn incremental processing "off" for PDF requests but
leave it "on" for HTML requests. In addition, you can follow the
<strong>same</strong> approach in order to utilize two
<strong>different</strong> XSLT processors when processing requests.
</p>
</s1>
<s1 title="Version">
<p>
At the time of this writing, this Snippet was tested against the Cocoon
version 2.0.3. Please note that this approach does not work with Cocoon 2.1.
Stay tuned for an upcoming Snippet which illustrates a different approach for
version 2.1.
</p>
</s1>
<s1 title="cocoon.xconf">
<p>
Here is a snippet from cocoon.xconf which declares a default XSLT processor.
It assumes the use of Xalan. You can see that the default XSLT processor is
configured to allow the incremental processing of SAX events. Check your
cocoon.xconf file, as the value for incremental-processing may be different
from what is shown here.
</p>
<source><![CDATA[
<xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"
logger="core.xslt-processor">
<parameter name="use-store" value="true"/>
<parameter name="incremental-processing" value="true"/>
</xslt-processor>
]]></source>
<p>
As discussed above, we need the ability to turn incremental processing of our
XSLT processor both on and off. Even though we are using the same XSLT
processor implementation, we need to declare an additional component in our
cocoon.xconf file in order to use the XSLT processor differently. So, in the
next snippet, we add a new component (as a child element of the root cocoon
element) to cocoon.xconf. Don't be concerned if you don't see any other
component declarations like this in the particular cocoon.xconf file you happen
to be using.
</p>
<source><![CDATA[
<component
role="org.apache.cocoon.components.xslt.XSLTProcessor/NotIncremental"
class="org.apache.cocoon.components.xslt.XSLTProcessorImpl">
<parameter name="use-store" value="true"/>
<parameter name="incremental-processing" value="false"/>
</component>
]]></source>
<p>
In the snippet above, the component is identified by the role it plays. Note
the value for the role attribute:
"org.apache.cocoon.components.xslt.XSLTProcessor/NotIncremental". We will use
this value in additional snippets below. Note also that the
incremental-processing parameter and its value of "false" is also specified in
this particular snippet.
</p>
</s1>
<s1 title="sitemap.xmap">
<p>Next, we need to add one more XSLT transformer component to the components
declaration section of our sitemap.xmap file.</p>
<source><![CDATA[
<map:components>
<!-- other map:components here -->
<map:transformers>
<!-- other map:transformers here -->
<map:transformer
name="xslt-notinc"
src="org.apache.cocoon.transformation.TraxTransformer"
logger="sitemap.transformer.xslt"
pool-max="32" pool-min="8" pool-grow="2">
<use-request-parameters>false</use-request-parameters>
<use-browser-capabilities-db>false</use-browser-capabilities-db>
<use-deli>false</use-deli>
<xslt-processor-role>
org.apache.cocoon.components.xslt.XSLTProcessor/NotIncremental
</xslt-processor-role>
</map:transformer>
<!-- other map:transformers here -->
</map:transformers>
<!-- other map:components here -->
</map:components>
]]></source>
<p>
In the snippet above, we are using the value for the role attribute,
specified earlier in the cocoon.xconf snippet, for the value of
xslt-processor-role element. Note also that we are giving this transformer the
name "xslt-notinc". Please note that the text node for xslt-processor-role was
manually broken across several lines for page viewing purposes only. Do not do
this in your sitemap.xmap file.
</p>
<p>Finally, in the relevant map:match elements in our sitemap.xmap, we can
specify exactly which xslt transformer component to use by supplying its name
as map:transformer's type attribute. Remember that the default xslt
transformer, as declared in cocoon.xconf, has incremental processing turned on.
Because it's the <em>default</em> transformer, you don't need to specify its
name in map:transform's type attribute. In fact, you don't have to supply a
type attribute at all when you use default components.</p>
<source><![CDATA[
<map:pipeline>
<!-- incremental processing = false -->
<map:match pattern="*.pdf">
<map:generate src="docs/{1}.xml"/>
<map:transform type="xslt-notinc" src="stylesheets/page2fo.xsl"/>
<map:serialize type="fo2pdf"/>
</map:match>
<!-- incremental processing = true -->
<map:match pattern="*.html">
<map:generate src="docs/{1}.xml"/>
<map:transform src="stylesheets/page2html.xsl"/>
<map:serialize type="html"/>
</map:match>
</map:pipeline>
]]></source>
</s1>
<s1 title="Comments">
<p>
Care to comment on this Snippet? Got another tip? Help keep this Snippet
relevant by passing along any useful feedback to the <link
href="mailto:[email protected]">cocoon users list.</link>
</p>
</s1>
</body>
</document>
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]