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:transforme r name="GoopExtra ctor"
src="org.apache .cocoon.transfo rmation.Fragmen tExtractorTrans former">
<extract-uri>GoopNamespa ce</extract-uri>
<extract-element>goop</extract-element>
</map:transformer >
<map:transforme r name="GleepExtr actor"
src="org.apache .cocoon.transfo rmation.Fragmen tExtractorTrans former">
<extract-uri>GleepNamesp ace</extract-uri>
<extract-element>gleep</extract-element>
</map:transformer >
An example xml document might contain:
...
<goop xmlns="GoopName space"/>
<goop xmlns="GoopName space"/>
<gleep xmlns="GleepNam espace"/>
...
+Lots of other elements handled directly by the stylesheet
The pipeline for the document:
<map:match pattern="**.wei rd">
<map:generate src="{1}.mxml"/>
<map:transfor m type="GoopExtra ctor"/>
<map:transfor m type="GleepExtr actor"/>
<map:transfor m type="xslt" src="stylesheet .xsl"/>
<map:serializ e 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="GoopName space"
xmlns:fe="http://apache.org/cocoon/fragmentextract or/2.0"
fragment-id="123"/>
<fe:fragment xmlns="GoopName space"
xmlns:fe="http://apache.org/cocoon/fragmentextract or/2.0"
fragment-id="456"/>
<fe:fragment xmlns="GleepNam espace"
xmlns:fe="http://apache.org/cocoon/fragmentextract or/2.0"
fragment-id="789"/>
It would be very nice if the FragmentExtract orTransformer 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:fragm ent?????">
<img src="cocoon/goop/{@fragment-d}.gif/>
</xsl:template>
<!-- Template for gleep fragments -->
<xsl:template match="fe:fragm ent?????">
<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:serializ e type="GoopSeria lizer"/>
</map:match>
<map:match pattern="gleep/*.gif">
<map:generate type="extractor " src="{1}"/>
<map:serializ e type="GleepSeia lizer"/>
</map:match>
The GoopSerializer and GleepSerializer are java programs I write
that transform the information in goops and gleeps into gifs.
Thanks,
Hugh Sparks, hu**@csparks.co m