By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Distinguishing fragments from Cocoon FragmentExtractorTransformer

P: n/a
If I configure and use two different fragment extractors on the
same XML document, how can I write xslt template match
patterns that distinguish which elements these fragments replaced?


My xml document contains, among other elements, two distinct
elements that need external java processing by a custom-made
Cocoon serializer that converts the contents of these elements
to "other stuff".

To extract each of these elements, I define two fragment extractors
in my sitemap:

<map:transformer name="GoopExtractor"
src="org.apache.cocoon.transformation.FragmentExtr actorTransformer">

<map:transformer name="GleepExtractor"
src="org.apache.cocoon.transformation.FragmentExtr actorTransformer">

An example xml document might contain:

<goop xmlns="GoopNamespace"/>
<goop xmlns="GoopNamespace"/>
<gleep xmlns="GleepNamespace"/>
+Lots of other elements handled directly by the stylesheet

The pipeline for the document:

<map:match pattern="**.weird">
<map:generate src="{1}.mxml"/>
<map:transform type="GoopExtractor"/>
<map:transform type="GleepExtractor"/>
<map:transform type="xslt" src="stylesheet.xsl"/>
<map:serialize type="html"/>

The xml seen by the stylesheet will have the goop and gleep elements
replaced by
fe:fragments. Using the sample xml with two goops and one gleep shown above,
the input to the stylesheet would be:

<fe:fragment xmlns="GoopNamespace"
<fe:fragment xmlns="GoopNamespace"
<fe:fragment xmlns="GleepNamespace"

It would be very nice if the FragmentExtractorTransformer put in an
attribute for the
element name it replaced. Something like: fragment-name="goop"
Unfortunately, this is not the case.
Note the apparently spurious default namespace defined in each fe:fragment:
This appears to be the only way to tell which element type the fragment

Now for the problem:
I want to have two templates in the stylesheet: One that matches fragments
that replaced the goop elements
and one that matches fragments that replaced the gleep elements. How should
the match patterns be written?
To be totally concrete:

<!-- Template for goop fragments -->

<xsl:template match="fe:fragment?????">
<img src="cocoon/goop/{@fragment-d}.gif/>

<!-- Template for gleep fragments -->

<xsl:template match="fe:fragment?????">
<img src="cocoon/gleep/{@fragment-d}.gif/>

When the request for the src="..." goes back to the server, the sitemap
it and processes the extracted fragments using a special serializer:

<map:match pattern="goop/*.giif">
<map:generate type="extractor" src="{1}"/>
<map:serialize type="GoopSerializer"/>
<map:match pattern="gleep/*.gif">
<map:generate type="extractor" src="{1}"/>
<map:serialize type="GleepSeializer"/>

The GoopSerializer and GleepSerializer are java programs I write
that transform the information in goops and gleeps into gifs.


Hugh Sparks, hu**
Jul 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.