You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by gerritjan <ge...@mac.com> on 2003/10/14 21:37:32 UTC

What's "wrong" with use of the document() function in Cocoon?

Hello,

Using the document() function for aggregation in Cocoon may break 
Separation of Concerns (SoC). That is, the designers of Cocoon view 
inclusion and transformation as different functions, best handled by 
separate Cocoon components. Treating them separately allows you to 
achieve performance gains and increases the resusability of your 
pipelines.

Having read the above I've a question.
I'm working on a navigation bar for our website (www.cdls-nl.org) that 
is cocoon-ized right now.
The idea is that we have an article's repository of xml-files. All 
these xml-files have a XML tag in which menu the file should show up. 
Our editors can choose from 6 menu's. (example shows munu1 from 6 menus)
It looks like this...
<articles>
   <article title="title" menu="menu1" protection="Members only>
      <content>
        ..........
      </content>
   </article>
<articles>

This repository is just a placeholder where the editors should post 
their content. Cocoon should figure out which documents show up in 
which menu.

If a site vistor would link to www.cdls-nl.org/menu1_index.html the 
list should be created dynamically by looking at all the latest (50) 
files in the repository.
I achieved that by
    <map:match pattern="*_index.html">
      <map:aggregate element="PAGINA">
        <map:part src="cocoon:/header_{1}.xml"/>
        <map:part src="cocoon:/index_{1}.xml"/>
      </map:aggregate>
      <map:transform src="style/xsl/index2html.xsl"/>
      <map:serialize/>
    </map:match>

    <map:match pattern="header_*.xml">
       <map:generate src="content/site_index.xml"/>
       <map:transform src="style/xsl/page_header.xsl">
         <map:parameter name="p_menu" value="{1}"/>
       </map:transform>
       <map:serialize type="xml"/>
    </map:match>

    <map:match pattern="index_*.xml">
        <map:generate type="directory" src="content/artikelen">
          <map:parameter name="depth" value="2"/>
          <map:parameter name="sort" value="name"/>
          <map:parameter name="include" value="\.x.*$"/>
        </map:generate>
       <map:transform src="style/xsl/menu_2.xsl">
         <map:parameter name="p_menu" value="{1}"/>
       </map:transform>
       <map:serialize type="xml"/>
    </map:match>

The header-stuff creates information for a page header
The index stuff uses (untill now) the directory generator, to come up 
with a list of xml files which is processed by a XSLT with a parameter, 
in this case it would be 'menu1'

This has the document() function. (see below)
   <xsl:template match="dir:directory" >
     <xsl:for-each select="dir:file">
        <xsl:variable 
name="xml_bestand">../../content/articles/<xsl:value-of 
select="@name"/></xsl:variable>
        <xsl:apply-templates 
select="document($xml_bestand)/child::onderwerpen/child::onderwerp" 
mode="index"/>
     </xsl:for-each>
   </xsl:template>

   <xsl:template match="onderwerp" mode="index">
     <xsl:choose>
      <xsl:when test="translate(@menu,'SOKNI','sokni')= $p_menu">
         <MENU_ITEM>
           <MENU_TITEL>
            <xsl:value-of select="@titel"/>
           </MENU_TITEL>
           <BEVEILIGING>
            <xsl:value-of select="@beveiliging"/>
           </BEVEILIGING>
         </MENU_ITEM>
      </xsl:when>
      <xsl:otherwise/>
     </xsl:choose>
   </xsl:template>
Question's
Am I mixing concerns here?
How can I avoid document()?
  It looks to me that if I would like only certain files that the 
Xdirectory generator would need that information in the XPATH 
parameter, is that possible?

Gerritjan

Re: What's "wrong" with use of the document() function in Cocoon?

Posted by Javier del Gesu <de...@thinknola.com>.
* Tony Collen <co...@umn.edu> [2003-10-14 20:53]:
> gerritjan wrote:
> 
> >Hello,

> >Using the document() function for aggregation in Cocoon may break 
> >Separation of Concerns (SoC). That is, the designers of Cocoon view 
> >inclusion and transformation as different functions, best handled by 
> >separate Cocoon components. Treating them separately allows you to 
> >achieve performance gains and increases the resusability of your pipelines.
> 
> <snip what="code"/>
> 
> >Question's
> >Am I mixing concerns here?
> 
> I think so, but I'm no expert :)
> 
> >How can I avoid document()?
> 
> Use the CInclude transformer.  Specifically, I bet you could cleverly 
> combine the DirectoryGenerator, and the CIncludeTransformer in a way to 
> duplicate this functionality.

> I would expect the pipeline snippit to look something like this:

> <map:match pattern="autoindex">
>   <map:generate type="directory" src="any/dir/"/>
>   <map:transform src="xslt/dir2cinclude.xsl"/>
>   <map:transform type="cinclude"/>
>   <map:transform src="xslt/listing2html.xsl"/>
>   <map:serialize type="xhtml"/>
> </map:match>

CInclude doesn't seem to have the control needed to do complicated
inclusions ala XInclude. How does one go about merging two XML
documents? Say you wanted to pull quotes out of a DocBook document
into a summary page? Indexing into documents, it seems that XSLT is
the best practice. (Trying to sort this out myself, third day with
Cocoon.)

-- 
Javier del Gesu - delgesu@thinknola.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: What's "wrong" with use of the document() function in Cocoon?

Posted by Alexander Schatten <al...@gmx.at>.
Tony Collen wrote:

> gerritjan wrote:
>
>> Hello,
>>
>> Using the document() function for aggregation in Cocoon may break 
>> Separation of Concerns (SoC). That is, the designers of Cocoon view 
>> inclusion and transformation as different functions, best handled by 
>> separate Cocoon components. Treating them separately allows you to 
>> achieve performance gains and increases the resusability of your 
>> pipelines.
>
>
I think in many cases various cocoon mechanism like includes or 
aggregation function are the best solution, however, there are several 
use cases where I believe, that the document() function is precious and 
creates easier to maintain code.

however, there are drawbacks, or at least effects one should know.

consider [document1] uses document() function to retrieve information 
from [document2]

if you modify [document2] and only [document1] is used in the sitemap, 
e.g. in the generator or transformer, cocoon does not realize, that 
there is a modification in the data and sends the old [document2] data.

so after modifying the dependend [document2] one should change also the 
main [document1] e.g. by using unix touch to show cocoon that there are 
changes and reload is necessary.

this is at least my experience, please correct my if I am wrong.

Alex


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: What's "wrong" with use of the document() function in Cocoon?

Posted by Tony Collen <co...@umn.edu>.
gerritjan wrote:

> Hello,
> 
> Using the document() function for aggregation in Cocoon may break 
> Separation of Concerns (SoC). That is, the designers of Cocoon view 
> inclusion and transformation as different functions, best handled by 
> separate Cocoon components. Treating them separately allows you to 
> achieve performance gains and increases the resusability of your pipelines.

<snip what="code"/>

> Question's
> Am I mixing concerns here?

I think so, but I'm no expert :)

> How can I avoid document()?

Use the CInclude transformer.  Specifically, I bet you could cleverly 
combine the DirectoryGenerator, and the CIncludeTransformer in a way to 
duplicate this functionality.

I would expect the pipeline snippit to look something like this:

<map:match pattern="autoindex">
   <map:generate type="directory" src="any/dir/"/>
   <map:transform src="xslt/dir2cinclude.xsl"/>
   <map:transform type="cinclude"/>
   <map:transform src="xslt/listing2html.xsl"/>
   <map:serialize type="xhtml"/>
</map:match>


dir2xinclude.xsl would then just transform the directory listing into 
cinclude statements, and the rest is simple.

>  It looks to me that if I would like only certain files that the 
> Xdirectory generator would need that information in the XPATH parameter, 
> is that possible?

Hmm, I'm not sure I follow you.  If you're talking about only including 
files which are named in a certain way, you can pass the xpathdirectory 
generator a "xmlFiles" parameter which contains a regexp to match files. 
  Check the docs at 
http://cocoon.apache.org/2.1/userdocs/generators/xpathdirectory-generator.html


> 
> Gerritjan


Regards,

Tony


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org