You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Markus Strickler <ma...@braindump.ms> on 2004/05/08 19:28:06 UTC

Selecting pipline based on XML content

Hi-

I'm looking for a way to determine the pipeline to use for rendering an 
XML document based on its content.
so if i have for example:

<page>
 <meta>
  <use-layout>a</use-layout>
 </meta>
 <content>
 <!-- some content -->
 </content>
</page>

I'd like to be able to use one pipeline, and if i have 
<use-layout>b</use-layout> I'd like to use another.
Is this possible? If so, how would you do it?

Thanks for any help,

-markus

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


Re: Selecting pipline based on XML content

Posted by Leon Widdershoven <qa...@dds.nl>.
I *know* it has been asked before, but I didn't follow the thread.

If no wizard steps in, you could have a look at:
marc.theaimsgroup.com

Threads which may be of interest:
http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=107909805318390&w=2
http://marc.theaimsgroup.com/?t=106272562800002&r=1&w=2

But if it's a very basic layout you're addressing you might also just 
switch the css file (if
you're dealing with html) or - as a hack - let the incoming URL have a 
request parameter
stating the layout to be used (it's easily switched on request 
parameters, session parameters
and sitemap parameters).

You might also want to look at the portal code (cocoon/samples). I think 
it uses a layout
based on the users profile. That may be put in the session when logging 
in, or encoded in the
url. I don't know but it's worth a look.

Leon

Markus Strickler wrote:

> Hi-
>
> I'm looking for a way to determine the pipeline to use for rendering 
> an XML document based on its content.
> so if i have for example:
>
> <page>
> <meta>
>  <use-layout>a</use-layout>
> </meta>
> <content>
> <!-- some content -->
> </content>
> </page>
>
> I'd like to be able to use one pipeline, and if i have 
> <use-layout>b</use-layout> I'd like to use another.
> Is this possible? If so, how would you do it?
>
> Thanks for any help,
>
> -markus
>
> ---------------------------------------------------------------------
> 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: Selecting pipline based on XML content

Posted by David Crossley <cr...@apache.org>.
Markus Strickler wrote:
> Hi-
> 
> I'm looking for a way to determine the pipeline to use for rendering an 
> XML document based on its content.

Apache Forrest selects different processing based on the
document type declaration of the xml instance using the
SourceTypeAction.

http://svn.apache.org/viewcvs.cgi/xml/forrest/trunk/src/core/context/forrest.xmap?root=Apache-SVN

--David


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


RE: Selecting pipline based on XML content

Posted by Conal Tuohy <co...@paradise.net.nz>.
Here's one way: use XSLT to transform your XML source doc into an xinclude
which refers to the layout. Then transform with xinclude transformer,
calling the appropriate pipeline.

e.g. sitemap:

<!-- pipeline "a" -->
<map:match pattern="a/**.html">
	<map:generate src="{1}.xml"/>
	<map:transform src="a.xsl"/>
	etc.
</map:match>

<!-- pipeline "b" -->
<map:match pattern="b/**.html">
	<map:generate src="{1}.xml"/>
	<map:transform src="b.xsl"/>
	etc.
</map:match>


<!-- pipeline for selecting transform based on content -->
<map:match pattern="**.html">
	<map:generate src="{1}.xml"/>
	<map:transform src="select-layout.xsl">
		<map:parameter name="uri" value="{1}.html"/>
	</map:transform>
	<map:transform type="xinclude"/>
	<map:serialize/>
</map:match>




select-layout.xsl:

<xsl:stylesheet etc>
	<xsl:param name="uri"/>
	<xsl:template match="/">
		<xi:include
			href="cocoon:/{page/meta/use-layout}/{$uri}"/>
	</xsl:template>
</xsl:stylesheet>

But be aware! This is the notorious "reactor pattern" which used to drive
Cocoon but which was deprecated in Cocoon 2. Similar pattern to embedding
references to XSL stylesheets in XML files as XML processing instructions.
The pattern has serious weaknesses - it's not good for maintenance or for
multi-purposing. I don't know why you use this pattern (you may have good
reason), but you may want to reconsider it.

Also if your different layouts are just different XSLT then you can use the
metastylesheet pattern (see the wiki). Similar to the above, except that the
you have a single pipeline for all your layouts, but the layout transform
stylesheet is generated from the source using a different pipeline, e.g.


<map:generate src="{1}"/>
<map:transform src="cocoon:/get-stylesheet-for/{1}"/>

Cheers

Con

> -----Original Message-----
> From: Markus Strickler [mailto:markus@braindump.ms]
> Sent: Sunday, 9 May 2004 05:28
> To: users@cocoon.apache.org
> Subject: Selecting pipline based on XML content
>
>
> Hi-
>
> I'm looking for a way to determine the pipeline to use for
> rendering an
> XML document based on its content.
> so if i have for example:
>
> <page>
>  <meta>
>   <use-layout>a</use-layout>
>  </meta>
>  <content>
>  <!-- some content -->
>  </content>
> </page>
>
> I'd like to be able to use one pipeline, and if i have
> <use-layout>b</use-layout> I'd like to use another.
> Is this possible? If so, how would you do it?
>
> Thanks for any help,
>
> -markus
>
> ---------------------------------------------------------------------
> 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