|
|
For Best Practice XMAP programming, there should be one and only one match for a URL. Use nesting when patterns will overlap. Nesting is using a Match tag inside another Match tag. It allows default Pipelines and other cool tricks.
Basic Example of Nesting Matches
<map:pipeline>
<map:match pattern="**">
<map:match pattern="**.html">
<map:match pattern="*/something/*.html">
<!-- Special Case -->
</map:match>
<!-- Default HTML -->
</map:match>
<!-- Default (Not HTML) -->
</map:match>
</map:pipeline>
Processing continues through the matches (as if they were IF statements) until one if these RETURN statements:
<map:serialize/> - Return the current data. Defaults to type="html", but type="xml" is common for internal pipelines.
<map:redirect-to uri="newURL"/> - Just go somewhere else.
Good Example for formatting for most XMAPs
<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:resources>
<map:resource name="finish-html">
<map:transform type="i18n">
<map:parameter name="locale" value="{page-envelope:document-language}"/>
</map:transform>
<map:transform src="../../xslt/util/strip_namespaces.xsl"/>
<map:transform src="xslt/page2xhtml.xsl">
<map:parameter name="root" value="/{page-envelope:publication-id}/live"/>
<map:parameter name="language" value="{page-envelope:document-language}"/>
</map:transform>
</map:resource>
</map:resources>
<map:pipelines>
<map:pipeline>
<map:match pattern="**">
<!-- "Main" Entry Pipeline>
<map:match pattern="**/main*">
<map:generate src="myfunction\main.xml"/>
<map:transform src="myfunction\main.xsl"/>
<map:match type="step" pattern="xml">
<map:serialize type="xml"/>
</map:match>
<map:transform src="myfunction\report.xsl"/>
<map:call resource="finish-html"/>
</map:match>
<!-- Subpipelines for preprocessing inputs -->
<map:match pattern="sub1">
<map:generate src="content\live\sitetree.xml"/>
<map:transform src="myfunction\site.xsl"/>
<map:serialize type="xml"/>
</map:match>
<map:match pattern="sub2">
<map:generate src="myfunction\site2.xml"/>
<map:transform src="myfunction\site2.xsl"/>
<map:serialize type="xml"/>
</map:match>
<!-- "Other" Entry Pipeline -->
<map:match pattern="**/other*">
<map:aggregate element="content">
<map:part src="cocoon:/site"/>
<map:part src="cocoon:/description"/>
</map:aggregate>
<map:transform src="myfunction\content.xsl"/>
<map:match type="step" pattern="xml">
<map:serialize type="xml"/>
</map:match>
<map:call resource="finish-html"/>
</map:match>
<!-- Default Match -->
<map:generate type="html" src="default.html"/>
<map:call resource="finish-html"/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
There are 2 expected entry pipelines: Main and Other, and they allow "lenya.step=xml" in the querystring to show the HTML. (See Breakpoints for an alternate method.) Anything not caught by those Pipelines falls to the default. Every Pipeline returning HTML uses the "finish-html" Resource for easy code maintenance.
Example forcing ".html" extension
<map:match pattern="**">
<!-- Process HTML -->
<map:match pattern="**.html">
<!-- Normal process here -->
</map:match>
<!-- Default adds ".html" -->
<map:select type="parameter">
<map:parameter name="parameter-selector-test" value="{request:queryString}"/>
<map:when test="">
<map:redirect-to uri="{1}.html" />
</map:when>
<map:otherwise>
<map:redirect-to uri="{1}.html?{request:queryString}" />
</map:otherwise>
</map:select>
</map:match>
|