On Feb 6, 2004, at 4:13 AM, Polymorphic wrote:


Hi all,

I am a new user of Cocoon and planning to migrate a couple of sites. I
read the book "Cocoon Developers handbook", look through the wiki and
mailing list archives but was unable to find a solution to what I am
attempting - sorry if it's something that I have missed.

I would like to have a pipeline use different xsl transformers depending
on the xml document that is requested. I would prefer not to do this by
URI match, or anything visible to the end user, but only depending on how
the xml document is structured. The reason is this - I will have several
different xml documents containing the content, which in turn means that I
need different xslt documents for them. A URI match solution would works,
but is not really elegant.

Right.



Does anyone have an idea how to go about doing this? Is Flow the answer?
Can it be done in an easier way? I'm grateful for any pointers.

Try something like along these lines?:


<map:match pattern="documents/*">
<map:generate type="file" src="{0}.xml">
<map:transform type="xslt" src="cocoon:/internal/get-stylesheet/{0}.xml" />
<map:serialize />
</map:match>


<map:match pattern="internal/get-stylesheet/**">
        <map:generate type="file" src="{1}"  />
        <map:transform type="xslt" src="get-stylesheet.xsl" />
        <map:serialize type="xml" />
</map:match>

The get-stylesheet.xsl would have templates to recognize your various content structures, and return the XSLT contained in the appropriate stylesheet (defined elsewhere, presumably). You could stream that out directly using the Xpath document() function, or you could use Xinclude or Cinclude (if you do that, you'll need to add the appropriate transformer to the get-stylesheet pipeline). Bear in mind that since the Cocoon URI resolver is in effect for your XSLT processing, the "cocoon:" and "context:" pseudoprotocols are available to you within get-stylesheet.xsl, where they might come in handy...

If your design is such that your XML docs are tightly-coupled to the stylesheets, to the point where you could "hardwire" it by including an element in the XML doc that actually names the stylesheet that it wants to be processed with, then there's an easier way: the XMLFileModule input module. Then you would not the need auxilliary pipeline above nor the extra indirection of the "get-stylesheet.xsl".

Or — if each class of XML document declared a namespace that you could map to a stylesheet... I think the 'xmlns:foo' is visible as a document attribute using XMLFileModule. You could capture those into sitemap parameters, then use a series of ParameterMatchers nested within the outer matcher to invoke transformers based on the existence of a namespace. So this too would give you a sitemap-only solution.

I'm a Cocoon noob too though, so if any of the pros want to chime here and confirm/correct...? :-)

HTH,
~ml


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to