Distinguishing fragments from Cocoon FragmentExtractorTransformer

Discussion in 'XML' started by Hugh Sparks, Jul 30, 2004.

  1. Hugh Sparks

    Hugh Sparks Guest

    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,
    Hugh Sparks, Jul 30, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Varley

    Extracting XML fragments

    Roger Varley, Sep 2, 2003, in forum: Java
    Replies:
    3
    Views:
    735
    Toddy Marx
    Sep 4, 2003
  2. Thomas S.
    Replies:
    0
    Views:
    579
    Thomas S.
    Nov 12, 2004
  3. Luigi Donatello Asero

    Fragments broken

    Luigi Donatello Asero, Jul 19, 2004, in forum: HTML
    Replies:
    0
    Views:
    439
    Luigi Donatello Asero
    Jul 19, 2004
  4. Ksenia Marasanova

    extracting HTML fragments and counting words

    Ksenia Marasanova, Feb 18, 2005, in forum: Python
    Replies:
    0
    Views:
    288
    Ksenia Marasanova
    Feb 18, 2005
  5. Jared  Zimmerman

    syndicate fragments of RSS feed?

    Jared Zimmerman, Sep 1, 2006, in forum: HTML
    Replies:
    8
    Views:
    446
    Jared Zimmerman
    Sep 9, 2006
Loading...

Share This Page