Distinguishing fragments from Cocoon FragmentExtractorTransformer

H

Hugh Sparks

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?

Details:

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.FragmentExtractorTransformer">
<extract-uri>GoopNamespace</extract-uri>
<extract-element>goop</extract-element>
</map:transformer>

<map:transformer name="GleepExtractor"
src="org.apache.cocoon.transformation.FragmentExtractorTransformer">
<extract-uri>GleepNamespace</extract-uri>
<extract-element>gleep</extract-element>
</map:transformer>

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"/>
</map:match>

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"
xmlns:fe="http://apache.org/cocoon/fragmentextractor/2.0"
fragment-id="123"/>
<fe:fragment xmlns="GoopNamespace"
xmlns:fe="http://apache.org/cocoon/fragmentextractor/2.0"
fragment-id="456"/>
<fe:fragment xmlns="GleepNamespace"
xmlns:fe="http://apache.org/cocoon/fragmentextractor/2.0"
fragment-id="789"/>

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
replaced.

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/>
</xsl:template>

<!-- Template for gleep fragments -->

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

When the request for the src="..." goes back to the server, the sitemap
matches
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>


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

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

Thanks,

Hugh Sparks, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top