One of the CocoonConditionals

A selector allows simple control logic to be embedded inside a Sitemap. Logic can be a simple if-then-else structure, or a switch statement. They are similar to Matcher in the tests they can perform, but are more flexible: matchers simply define whether a pipeline is evaluated or not (essentially a simple if statement). Selectors can drive processing down multiple routes.

There are several selectors available. These can perform similar operations to the equivalent matchers.


Selectors are declared in the sitemap, as follows:

<map:selectors default="browser">
  <map:selector name="load"

  <map:selector name="user"

<map:selector name="browser" 
  <browser name="explorer" useragent="MSIE"/>
  <browser name="lynx" useragent="Lynx"/>
  <browser name="mozilla5" useragent="Mozilla/5"/>
  <browser name="mozilla5" useragent="Netscape6/"/>
  <browser name="netscape" useragent="Mozilla"/>

Note the default attribute which defines the default selector for pipelines that don't explicitly define one.


Example usage (note similarity with xsl:choose):

<map:match pattern="*">
  <map:generate type="serverpages" src="test/{1}.xsp"/>

  <map:select type="browser">
  <!-- you could insert parameters here as well -->
   <map:when test="explorer">
    <map:transform src="stylesheets/w3c-2-msie.xsl"/>
   <map:when test="lynx">
    <map:transform src="stylesheets/dynamic-page2html-text.xsl"/>
   <map:when test="netscape">
    <map:transform src="stylesheets/ns4.xsl"/>
    <map:transform src="stylesheets/w3c.xsl"/>

  <map:transform src="stylesheets/dynamic-page2html.xsl"/>

Available Implementations

Selector (last edited 2009-09-20 23:41:56 by localhost)