Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

How to pass variables from XMAPs to XSL files.

There are two types of variables in XMAPs.
1. Standard variables are listed below. Download the Usecase for the full list and example code.
2. Match parts are assigned to number variables. They can be assigned by calling Pipelines from other Pipelines. These are described first because the description is much shorter.

Parts of the Match Pattern

Each * or ** in a pattern is assigned to a number:
{1} = "partA/partB" from the **
{2} = "partC"
{3} = "partD"
To rebuild the original, provide all the parts including any static text:

When using Nested Matches, you can retrieve parts of the previous patterns using double-dots: {../#}

These are useful for 2 purposes:
1. Removing static text.
The example above removed the ".html" from the variables.

2. Assigning a "mode" (as in XSL) to a Pipeline.

The Default publication's publication-sitemap.xmap uses this technique:
<map:generate src="cocoon:/lenyabody-edit/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/>
<map:generate src="cocoon:/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/>

Both statements match:
<map:match pattern="lenyabody-*/*/*/*/**">

{1} is then passed to other pipelines:
<map:part src="cocoon:/lenya-document-{1}/{3}/{4}/{page-envelope:document-path}"/>
and for process control:
<map:select type="parameter">
<map:parameter name="parameter-selector-test" value="{1}"/>
<map:when test="view">
<map:transform type="link-rewrite"/>

Standard Variables

For example code containing every standard variable (including the useless ones), download these two files to your publication directory:
Variables Usecase
Variables XSLT

Open any document in the publication using a web browser. Add "?lenya.usecase=variables" to the URL Address to see the variables.


To use a value requires 3 lines:
1. The XMAP sets a parameter:
<map:transform src="variables.xsl">
<map:parameter name="doctype" value="{page-envelope:document-type}"/>

NOTE: If you repeat a parameter name, only one value, usually the last, will be used.

2. The transformation receives the parameter:
<xsl:param name="doctype"/>

3. The transformation uses the parameter:
DOCTYPE=<xsl:value-of select="$doctype"/>


From a performance perspective, it should not matter which variable is used.  Lenya decides the area for each URL before getting to the publication-sitemap.  Lenya permanently caches the doctype the first time a document is accessed (although that is considered a bug.) Lenya assigns the matcher (numbered) variables during each match.  Processing any of those variables is a simple memory lookup.

The advantage of using the matcher variables is they can be changed during processing. Using Multiple Stylesheets for the Same Content has a Usecase which passes control to the publication-sitemap but substitutes a different doctype.  That would not have been possible if the doctype variable was used in the normal pipeline.

<< ContentCommon >>

Contact Solprovider
Paul Ercolino