Curious guy :)
Have a look at the Java code generated for any XSP, and you'll
understand : this a local variable that is used by the XSP engine to
produce the attributes of XML elements. Since we have here a separate
method, this local variable is out of scope, and we must therefore
declare a new one with the same name.
Mario Muja wrote:
> Hi Sylvain,
> thank you for this hint.
>
> I do not understand, why the following line is necessary.
>
> AttributesImpl xspAttr = new AttributesImpl();
>
> Can you please explain this?
>
> Regards, Mario
>
>
> Sylvain Wallez wrote:
>
>> The capture taglib won't solve this problem, because the captured
>> content can't be parameterized.
>>
>> To achieve this, you can put the reused part in a method defined in a
>> <xsp:logic> block child of <xsp:page>. Below is an example, based on
>> simple.xsp form the samples.
>>
>> <xsp:page
>> language="java"
>> xmlns:xsp="http://apache.org/xsp"
>> xmlns:xsp-request="http://apache.org/xsp/request/2.0"
>> xmlns:log="http://apache.org/xsp/log/2.0"
>> xmlns:capture="http://apache.org/cocoon/capture/1.0"
>> >
>>
>> <xsp:logic>
>> private void reusedPart(String param) throws SAXException {
>> AttributesImpl xspAttr = new AttributesImpl();
>> <para>Hi there <xsp:expr>param</xsp:expr> ! I'm a simple dynamic
>> page generated by XSP (eXtensible Server Pages).</para>
>>
>> <para>I was requested as the URI: <b><xsp-request:get-uri
>> as="xml"/></b></para>
>>
>> }
>> </xsp:logic>
>> <page>
>> <log:logger name="xsp-sample" filename="xsp-sample.log"/>
>> <log:debug>Processing the beginning of the page</log:debug>
>>
>> <title>A Simple XSP Page</title>
>>
>> <content>
>>
>> <capture:fragment-variable name="page_part">
>> <para>These 2 paragraphs were generated at the start of the XSP,
>> and captured for insertion at the end.</para>
>>
>> <para>Brought to you by Cocoon2 at <xsp:expr>new
>> Date()</xsp:expr>.</para>
>> </capture:fragment-variable>
>>
>> <xsp:logic>reusedPart("first time");</xsp:logic>
>>
>> <xsp:logic>reusedPart("second time");</xsp:logic>
>>
>> <para>The following list was dynamically generated:</para>
>>
>> ..
>>
>> Hope this helps.
>>
>> Mario Muja wrote:
>>
>>> Hi Alexandru,
>>> reusing part of an XSP result is something I plan to achieve with the
>>> new logicsheet CAPTURE.XSL. You will find it under
>>>
>>> src\org\apache\cocoon\component\language\markup\xsp\java
>>>
>>> in the source tree of the 2.0 and 2.1 branch. This logicsheet
>>> contains markup to copy part of an XSP to an XMLFragment variable,
>>> which can be later output using
>>>
>>> <xsp:expr>here put the name of the fragment variable</xsp:expr>.
>>>
>>> I never used this logicsheet but I think that it can do what you have
>>> described. Please let us know about your experiences with this new
>>> logicsheet.
>>>
>>> Hope this helps.
>>> Mario
>>>
>>>
>>> Alexandru COSTIN wrote:
>>>
>>>> Hello,
>>>> I have created succesfully some dynamic pages using cocoon, but
>>>> I have one question about code reusability.
>>>> The main problem is that in the XSP file, I have XML trees that
>>>> are very similar, except for a parameter.
>>>>
>>>> I will paste a code snippet below
>>>>
>>>> <calevel>
>>>> <esql:execute-query>
>>>> <esql:query>
>>>> select * from v_inf where idtype_inf=6
>>>> </esql:query>
>>>> <esql:results>
>>>> <esql:row-results>
>>>> <row>
>>>>
>>>> <id_inf><esql:get-string
>>>> column="id_inf"/></id_inf>
>>>> <name_itm><esql:get-string
>>>> column="name_itm"/></name_itm>
>>>> </row>
>>>> </esql:row-results>
>>>> </esql:results>
>>>> </esql:execute-query>
>>>> </calevel>
>>>>
>>>> This part has to be repeated (with the same columns and
>>>> structure) with
>>>> idtype_inf=7,8, etc.
>>>> How can I do this without rewritting this code snippet x-times?
>>>> A standard include mecanism has to be possible in Cocoon, or this
>>>> can be
>>>> done otherwise.
>>>> I think I have a solution, but I don't know if it's the best
>>>> one. This part can be embedded in a XSP:logic loop that uses an array
>>>> with the 6,7,8 values and pass the values to the embedded part.
>>>> Alexandru
>>>>
>>>>
>>>
>
>
>
--
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>