Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Distinguishing fragments from Cocoon FragmentExtractorTransformer

Thread Tools

Distinguishing fragments from Cocoon FragmentExtractorTransformer

Hugh Sparks
Posts: 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, Removed)

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CrcAlign-Err and Fragments switchctidude Cisco 3 03-06-2005 09:17 PM
Tomcat+Struts+Cocoon: Good tutorials needed about Cocoon integration Thomas S. Java 0 11-12-2004 08:42 AM
many lost fragments on ppp-multilink connections Gerd Thuemmler Cisco 0 11-27-2003 07:54 AM
Extracting XML fragments Roger Varley Java 3 09-04-2003 06:14 PM
ppp multilink lost many fragments Gerd Thümmler Cisco 0 07-11-2003 08:05 AM