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()... gerritjan
- Re: What's "wrong" with use of the docum... Tony Collen
- Re: What's "wrong" with use of the d... Javier del Gesu
- Re: What's "wrong" with use of the d... Alexander Schatten
