cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conal Tuohy <con...@paradise.net.nz>
Subject RE: Selecting pipline based on XML content
Date Sat, 08 May 2004 23:59:10 GMT
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


Mime
View raw message