You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sébastien Geindre <se...@meteo.fr> on 2007/11/20 15:07:05 UTC

xpath condition on xml data in sitemap

hi all,

i need to make a conditional treatment in my sitemap :

generator --> transformer A -----(if condition on xml)-----> transformer 
B1 ----------|---> transformerC --> serializer
                                                          
(else)                          -----> transformer B2 ----------|

How can i make this condition on xml data in the stipe map ?
Which component should i use ?
the condition could be an xpath expression...

thanks for your help.

-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Sébastien Geindre <se...@meteo.fr>.
Robin Rigby a écrit :
> Something with an action [1] or XSP action [2]?
>
> generator
> transformer A
> action
> -- transformer B1
> -- transformer C
> -- serializer 
> transformer B2
> transformer C
> serializer 
>
> The action analyses the stream from transformer A and returns
> <action:set-success/> or <action:set-failure/>.  On success, the content of
> the action is executed:  tB1:tC:s and execution ends.  On failure, the
> content is skipped and execution continues.
>   
Interresting, i thought action was performed before the pipe execution.

The sitemap provides the following elements:

    * Redirector--to perform redirects within the Action based on your
      logic.
    * SourceResolver--to find resources.
    * Object Model--to gain access to the request, context, and session
      objects.
    * Source--the string defined in the "src" attribute in the Sitemap.
    * Parameters--the parameters defined in the Sitemap at runtime.

so in my custom action

 public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters params )
        throws Exception

where can i find my xml data ?
i have to parse it to check what i want to check

And if it is ok, it will return a hashmap.

will the transformer B1 be able to process the same xml data ?

thanks for help.



>  
> Robin
>
> [1] http://localhost/cocoondox/2.1/userdocs/concepts/actions.html
> [2] http://wiki.apache.org/cocoon/XSPAction
>  
>
> -----Original Message-----
> From: Sébastien Geindre [mailto:sebastien.geindre@meteo.fr] 
> Sent: 20 November 2007 14:07
> To: users@cocoon.apache.org
> Subject: xpath condition on xml data in sitemap
>
> hi all,
>
> i need to make a conditional treatment in my sitemap :
>
> generator --> transformer A -----(if condition on xml)-----> transformer 
> B1 ----------|---> transformerC --> serializer
>                                                           
> (else)                          -----> transformer B2 ----------|
>
> How can i make this condition on xml data in the stipe map ?
> Which component should i use ?
> the condition could be an xpath expression...
>
> thanks for your help.
>
>   


-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: xpath condition on xml data in sitemap

Posted by Robin Rigby <ro...@gondolier.org.uk>.
Something with an action [1] or XSP action [2]?

generator
transformer A
action
-- transformer B1
-- transformer C
-- serializer 
transformer B2
transformer C
serializer 

The action analyses the stream from transformer A and returns
<action:set-success/> or <action:set-failure/>.  On success, the content of
the action is executed:  tB1:tC:s and execution ends.  On failure, the
content is skipped and execution continues.
 
Robin

[1] http://localhost/cocoondox/2.1/userdocs/concepts/actions.html
[2] http://wiki.apache.org/cocoon/XSPAction
 

-----Original Message-----
From: Sébastien Geindre [mailto:sebastien.geindre@meteo.fr] 
Sent: 20 November 2007 14:07
To: users@cocoon.apache.org
Subject: xpath condition on xml data in sitemap

hi all,

i need to make a conditional treatment in my sitemap :

generator --> transformer A -----(if condition on xml)-----> transformer 
B1 ----------|---> transformerC --> serializer
                                                          
(else)                          -----> transformer B2 ----------|

How can i make this condition on xml data in the stipe map ?
Which component should i use ?
the condition could be an xpath expression...

thanks for your help.

-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Tobia Conforto <to...@linux.it>.
Sébastien Geindre wrote:
> i need to make a conditional treatment in my site
>
> generator
> transformer A
> if condition on xml from transformerA --> transformer B1
> else --> transformer B2
> transformer C
> serializer
>
> the condition is computed on xml data and global variables

What you ask for is not compatible with the way Cocoon works.
It is my understanding that Cocoon pipelines work like this:

1. a HTTP request reaches Cocoon;

2. the request is dispatched to the right (sub-)sitemap;

3. the tree of all matchers, selectors and actions in that sitemap is
   executed, meaning that each of them is asked (in hierarchical order)
   to make its decision and optionally perform any side effects.

What comes out of step 3. is a linear sequence of components, comprising
a generator, zero or more transformers and a serializer.  (Readers and
aggregators are chosen at this time too.)

4. This chain of components is then executed in a streaming fashion,
   meaning that the serializer can (in theory) start outputting the
   result document well before the generator is finished*;

5. the result of the serialization is sent as a HTTP response, again in
   a streaming, progressive way, at least in theory.

In any case, streaming or not, it should be clear that you cannot
choose what components to use in the pipeline (step 3.) based on the
intermediate results of the component chain itself (step 4.)

I suggest you either:

- make the choice between B1 and B2 based on the request data only, or

- merge transformers B1 and B2 in a single transformer, or

- always execute both transformers B1 and B2, controlling the function
  of each of them through appropriate elements in the XML stream, or

- delegate the work of B1 and B2 (and possibly of C and serialization)
  to appropriate sub-pipelines, using either the CInclude transformer,
  a piece of Flowscript, <map:redirect-to>, or similar means; remember
  to use cocoon:/ URLs in the place of http:// whenever you can, as they
  are optimized for internal sub-requests.

It's difficult to offer practical suggestions without knowing what your
pipeline does.

By the way, this whole email applies to Cocoon 2.1.  I don't know how
much of it is still true in 2.2.


Tobia

* A notable exception to this streaming behaviour is the XSL transformer,
in the general case anyway, as has been pointed out in other threads.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by dynnamitt <kj...@gmail.com>.
sorry, javadoc states:

"Caching and reloading can be turned on / off"

The problem is that the source-xml-uri has to be injected during the
request, right?

-> And that isn't something the
org.apache.cocoon.components.modules.input.XPathXMLFileModule
will NOT let us do I think..

Will someone wake up and smell the RE.S.T !!!!

Cocoon needs a QuerySelector that takes any URI and any XPath (giving a
boolean result)  as a parameter.

Kjetil Dynnamitt


dynnamitt wrote:
> 
> Yes you can BUT then the XML will be cached on startup... what if this is
> a RESTFUL GET "query" that has a variable URI? 
> 
> 
> Kjetil Dynnamitt
> 
> 
> Ralph Goers wrote:
>> 
>> Not quite true. You can accomplish this using XMLFileModule.
>> 
>> Joerg Heinicke wrote:
>>> What you outline we used to call content-based pipelines - and is not 
>>> yet supported. By intention in the first place but the opinions change 
>>> on this topic. You should find something in the archives.
>>>
>>> Joerg
>>>
>>>
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/xpath-condition-on-xml-data-in-sitemap-tp13857627p15801544.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by dynnamitt <kj...@gmail.com>.
Yes you can BUT then the XML will be cached on startup... what if this is a
RESTFUL GET "query" that has a variable URI? 


Kjetil Dynnamitt


Ralph Goers wrote:
> 
> Not quite true. You can accomplish this using XMLFileModule.
> 
> Joerg Heinicke wrote:
>> What you outline we used to call content-based pipelines - and is not 
>> yet supported. By intention in the first place but the opinions change 
>> on this topic. You should find something in the archives.
>>
>> Joerg
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/xpath-condition-on-xml-data-in-sitemap-tp13857627p15799981.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Ralph Goers <Ra...@dslextreme.com>.
Not quite true. You can accomplish this using XMLFileModule.

Joerg Heinicke wrote:
> What you outline we used to call content-based pipelines - and is not 
> yet supported. By intention in the first place but the opinions change 
> on this topic. You should find something in the archives.
>
> Joerg
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Joerg Heinicke <jo...@gmx.de>.
What you outline we used to call content-based pipelines - and is not 
yet supported. By intention in the first place but the opinions change 
on this topic. You should find something in the archives.

Joerg

On 22.11.2007 4:28 Uhr, Sébastien Geindre wrote:
> Bonjour,
> 
> is it impossible or my explanation are too 'messy' or my english too 
> scrambled ??
> just let me know...
> 
> thanks.
> 
> Seb
> 
> 
> Sébastien Geindre a écrit :
>> Hello  everybody,
>>>
>>> i need to make a conditional treatment in my sitemap :
>>>
>>> generator --> transformer A -----(if condition on xml)-----> 
>>> transformer B1 ----------|---> transformerC --> serializer
>>>                                                          
>>> (else)                          -----> transformer B2 ----------|
>> my schema is not very clear :
>>
>> generator
>> transformer A
>> if condition on xml from transformerA --> transformer B1
>> else -----> transformer B2
>> transformer C
>> serializer
>>
>> the condition is computed on xml data and global variables
>>
>> How can i do that ??
>>
>> thanks for your help.
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Ralph Goers <Ra...@dslextreme.com>.
We are using the pattern similar to below in many, many places in our 
application.  I should also note that we no longer use XMLFileModule but 
a new XPathXMLFileModule that I will be checking in shortly. 
XPathXMLFileModule works similar to XMLFileModule but it caches 
correctly and has more consistent performance.

In cocoon.xconf:
<component-instance 
class="org.apache.cocoon.components.modules.input.XMLFileModule" 
logger="core.modules.xml" name="globalConfig">
  <file src="cocoon://mySite/getGlobalConfig"/>
</component>

In mySite's sitemap:

<map:match pattern="getGlobalConfig">
  <map:generate src="{system-property:global-config"} type="file"/>
  <map:serialize type="xml">
</map:match>

<map:match pattern="main">
  <map:act type="session-propagator">
     <map:parameter name="myTest" 
value="{globalConfig:/global-variables/mode}"/>
  </map:act>
  <map:generate ...>
  <map:select type="session-attribute">
    <map:parameter name="attribute-name" value="myTest"/>
    <map:when test="true">
      <map:transform type="a"/>
    </map:when>
    <map:otherwise>
      <map:transform type="b"/>
    </map:otherwise>
  </map:select/>
  <map:serialize .../>
</map:match>

Sébastien Geindre wrote:
> Bonjour,
>
> is it impossible or my explanation are too 'messy' or my english too 
> scrambled ??
> just let me know...
>
> thanks.
>
> Seb
>
>
> Sébastien Geindre a écrit :
>> Hello  everybody,
>>>
>>> i need to make a conditional treatment in my sitemap :
>>>
>>> generator --> transformer A -----(if condition on xml)-----> 
>>> transformer B1 ----------|---> transformerC --> serializer
>>>                                                          
>>> (else)                          -----> transformer B2 ----------|
>> my schema is not very clear :
>>
>> generator
>> transformer A
>> if condition on xml from transformerA --> transformer B1
>> else -----> transformer B2
>> transformer C
>> serializer
>>
>> the condition is computed on xml data and global variables
>>
>> How can i do that ??
>>
>> thanks for your help.
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Dev at weitling <de...@weitling.net>.

Sébastien Geindre wrote:
> Dev at weitling a écrit :
>> Another idea would be writing a custom selector choosing the
>> transformer.
>>   
> custom selector ?
> it will make the test on xml, and this xml could be pass to next
> transformer ?

That was one of my dreams, looking at the API of Selector it just made
*plop* and was gone.

>> Flowscript will probably get you the fastest but it's neither elegant
>> nor its intention.
>>   
> if flowscript are not elegant, what is the best practice ?

As Robin Rigby pointed out you could use a custom Action. It isn't
elegant either but you could use <map:resource> to prevent redundant
pipeline code.

Seems you have found an ugly side of Cocoon ;-)

Florian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Sébastien Geindre <se...@meteo.fr>.
Dev at weitling a écrit :
> Well, my help looks like throwing a life-belt without a rope...
>
> If your transformer B1 and B2 are simple XSL you could merge their
> stylesheets and selecting the appropriate templates depending on your
> content.
>   
unfortunaletly, one of them is a custom transformer which make an http 
post to a web service
> Another idea would be writing a custom selector choosing the transformer.
>   
custom selector ?
it will make the test on xml, and this xml could be pass to next 
transformer ?
> Flowscript will probably get you the fastest but it's neither elegant
> nor its intention.
>   
if flowscript are not elegant, what is the best practice ?
> Please drop a line which solution you'll have chosen, perhaps others may
> appreciate for their own problems.
>   
no problem !
> Bye,
> Florian
>
> Sébastien Geindre wrote:
>   
>> the B1 transformer post http request to a webservice
>> the B2 just transform XML data
>>
>> A transformer compute :
>> - intersection between gml polygons : one the the http post request
>> (get by stream generator), one hard coded (properties of application)
>> - it also makes comparison between attribute of the http post request
>> and properties of application
>>
>> if the intersection and the comparison are ok, then transformer B1
>> should be called..
>>
>> I thought about kinf of xpathselector
>>
>> perhaps, i have to do this with flowscipt....
>>
>> thanks for answered, and started the discussion.
>> it 's pipeline design question, and it seems thaht i am lost.... :-)
>>       
>>     
>>>>> my schema is not very clear :
>>>>>
>>>>> generator
>>>>> transformer A
>>>>> if condition on xml from transformerA --> transformer B1
>>>>> else -----> transformer B2
>>>>> transformer C
>>>>> serializer
>>>>>
>>>>> the condition is computed on xml data and global variables
>>>>>           
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>   


-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Dev at weitling <de...@weitling.net>.
Well, my help looks like throwing a life-belt without a rope...

If your transformer B1 and B2 are simple XSL you could merge their
stylesheets and selecting the appropriate templates depending on your
content.
Another idea would be writing a custom selector choosing the transformer.
Flowscript will probably get you the fastest but it's neither elegant
nor its intention.

Please drop a line which solution you'll have chosen, perhaps others may
appreciate for their own problems.

Bye,
Florian

Sébastien Geindre wrote:
> the B1 transformer post http request to a webservice
> the B2 just transform XML data
>
> A transformer compute :
> - intersection between gml polygons : one the the http post request
> (get by stream generator), one hard coded (properties of application)
> - it also makes comparison between attribute of the http post request
> and properties of application
>
> if the intersection and the comparison are ok, then transformer B1
> should be called..
>
> I thought about kinf of xpathselector
>
> perhaps, i have to do this with flowscipt....
>
> thanks for answered, and started the discussion.
> it 's pipeline design question, and it seems thaht i am lost.... :-)
>       
>>>> my schema is not very clear :
>>>>
>>>> generator
>>>> transformer A
>>>> if condition on xml from transformerA --> transformer B1
>>>> else -----> transformer B2
>>>> transformer C
>>>> serializer
>>>>
>>>> the condition is computed on xml data and global variables

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Sébastien Geindre <se...@meteo.fr>.
Dev at weitling a écrit :
> Hi Sébastien,
>
> I'm not the Cocoon guru around here, but could you elaborate on the kind
> of xml condition?
> Perhaps there is help :-)
>   
ok i'll try:

the B1 transformer post http request to a webservice
the B2 just transform XML data

A transformer compute :
- intersection between gml polygons : one the the http post request (get 
by stream generator), one hard coded (properties of application)
- it also makes comparison between attribute of the http post request 
and properties of application

if the intersection and the comparison are ok, then transformer B1 
should be called..

I thought about kinf of xpathselector

perhaps, i have to do this with flowscipt....

thanks for answered, and started the discussion.
it 's pipeline design question, and it seems thaht i am lost.... :-)
> Florian
>
>
> Sébastien Geindre wrote:
>   
>> Bonjour,
>>
>> is it impossible or my explanation are too 'messy' or my english too
>> scrambled ??
>> just let me know...
>>
>> thanks.
>>
>> Seb
>>
>>
>> Sébastien Geindre a écrit :
>>     
>>> Hello  everybody,
>>>       
>>>> i need to make a conditional treatment in my sitemap :
>>>>
>>>> generator --> transformer A -----(if condition on xml)----->
>>>> transformer B1 ----------|---> transformerC --> serializer
>>>>                                                         
>>>> (else)                          -----> transformer B2 ----------|
>>>>         
>>> my schema is not very clear :
>>>
>>> generator
>>> transformer A
>>> if condition on xml from transformerA --> transformer B1
>>> else -----> transformer B2
>>> transformer C
>>> serializer
>>>
>>> the condition is computed on xml data and global variables
>>>
>>> How can i do that ??
>>>
>>> thanks for your help.
>>>
>>>       
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>   


-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Dev at weitling <de...@weitling.net>.
Hi Sébastien,

I'm not the Cocoon guru around here, but could you elaborate on the kind
of xml condition?
Perhaps there is help :-)

Florian


Sébastien Geindre wrote:
> Bonjour,
>
> is it impossible or my explanation are too 'messy' or my english too
> scrambled ??
> just let me know...
>
> thanks.
>
> Seb
>
>
> Sébastien Geindre a écrit :
>> Hello  everybody,
>>>
>>> i need to make a conditional treatment in my sitemap :
>>>
>>> generator --> transformer A -----(if condition on xml)----->
>>> transformer B1 ----------|---> transformerC --> serializer
>>>                                                         
>>> (else)                          -----> transformer B2 ----------|
>> my schema is not very clear :
>>
>> generator
>> transformer A
>> if condition on xml from transformerA --> transformer B1
>> else -----> transformer B2
>> transformer C
>> serializer
>>
>> the condition is computed on xml data and global variables
>>
>> How can i do that ??
>>
>> thanks for your help.
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Sébastien Geindre <se...@meteo.fr>.
Bonjour,

is it impossible or my explanation are too 'messy' or my english too 
scrambled ??
just let me know...

thanks.

Seb


Sébastien Geindre a écrit :
> Hello  everybody,
>>
>> i need to make a conditional treatment in my sitemap :
>>
>> generator --> transformer A -----(if condition on xml)-----> 
>> transformer B1 ----------|---> transformerC --> serializer
>>                                                          
>> (else)                          -----> transformer B2 ----------|
> my schema is not very clear :
>
> generator
> transformer A
> if condition on xml from transformerA --> transformer B1
> else -----> transformer B2
> transformer C
> serializer
>
> the condition is computed on xml data and global variables
>
> How can i do that ??
>
> thanks for your help.
>


-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xpath condition on xml data in sitemap

Posted by Sébastien Geindre <se...@meteo.fr>.
Hello  everybody,
>
> i need to make a conditional treatment in my sitemap :
>
> generator --> transformer A -----(if condition on xml)-----> 
> transformer B1 ----------|---> transformerC --> serializer
>                                                          
> (else)                          -----> transformer B2 ----------|
my schema is not very clear :

generator
transformer A
if condition on xml from transformerA --> transformer B1
else -----> transformer B2
transformer C
serializer

the condition is computed on xml data and global variables

How can i do that ??

thanks for your help.

-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org