HOME | NEWS | FAQ | DOCUMENTATION | DOWNLOADS | SITE MAP | CONTACTS/LINKS

Selectors

Selectors are the conditional constructions for sitemaps. The most commonly used one is the BrowserSelector which allows different routes in the pipeline dependant on the client's browser. Useful for differences in browser behaviour. The Paloose site makes use of this so that the text based Lynx and the iPhone browser are supported.

Component Declaration

Selectors are defined in the component declaration part of the Sitemap.

<map:selectors default="browser"> <map:selector name="browser" src="resource://lib/selection/BrowserSelector"> <map:browser name="explorer" useragent="MSIE"/> ... </map:selector> </map:selectors>

The default attribute specifies the type of selector to use if none is specified in a pipeline.

BrowserSelector

The root sitemap needs to have the BrowserSelector declared as a component:

<map:components> ... <map:selectors default="browser"> <map:selector name="browser" src="resource://lib/selection/BrowserSelector"> <map:browser name="explorer" useragent="MSIE"/> <map:browser name="pocketexplorer" useragent="MSPIE"/> <map:browser name="handweb" useragent="HandHTTP"/> <map:browser name="avantgo" useragent="AvantGo"/> <map:browser name="imode" useragent="DoCoMo"/> <map:browser name="opera" useragent="Opera"/> <map:browser name="lynx" useragent="Lynx"/> <map:browser name="java" useragent="Java"/> <map:browser name="wap" useragent="Nokia"/> <map:browser name="wap" useragent="UP"/> <map:browser name="wap" useragent="Wapalizer"/> <map:browser name="mozilla5" useragent="Mozilla/5"/> <map:browser name="mozilla5" useragent="Netscape6/"/> <map:browser name="netscape" useragent="Mozilla"/> <map:browser name="safari" useragent="Safari"/> <map:browser name="iphone" useragent="iPhone"/> </map:selector> </map:selectors> ... </map:components>

where

  • name — the name of this selector (in this case browser).
  • src — the location of the PHP package for this component.

Each sub-element, <map:browser>, defines a particular browser by its user agent type, where

  • name — the name of the selection when used in the pipeline.
  • useragent — the client browser defined by its agent.

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount or reader pipeline element. For example (from this site):

<map:match pattern="**.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/headings.xml" element="headings" strip-root="true"/> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/newsArticles.xml" element="news-articles" strip-root="true"/> <map:part src="cocoon:/{1}.xml" element="content" strip-root="true"/> </map:aggregate> <map:select type="browser"> <map:when test="lynx"> <map:transform src="context://resources/transforms/page2lynx.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> </map:when> <map:otherwise> <map:transform src="context://resources/transforms/page2html.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> </map:otherwise> </map:select> <map:transform src="context://resources/transforms/stripNamespaces.xsl"/> <map:serialize type="html" /> </map:match>

RequestParameterSelector

The sitemap needs to have the RequestParameterSelector declared as a component:

<map:selectors default="browser"> ... <map:selector name="request-parameter" src="resource://lib/selection/RequestParameterSelector"> <map:parameter-name>type</map:parameter-name> </map:selector> </map:selectors>

where

  • name — the name of this selector (in this case request-parameter).
  • src — the location of the PHP package for this component.

The <map:paraneter-name> tag defines a the default test parameter in the query string if one is not defined in the pipeline (in this case 'type'.

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount, call or reader pipeline element. For example (from the Chandos Symphony Orchestra site):

<map:match pattern="*.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/newsArticles.xml" element="newsArticles" strip-root="true"/> <map:part src="cocoon:/futureConcerts.xml" element="futureConcerts" strip-root="true"/> <map:part src="cocoon:/{1}.xml" element="content" strip-root="true"/> </map:aggregate> <map:select type="request-parameter"> <map:parameter name="parameter-name" value="type"/> <map:when test="xml"> <map:transform src="context://resources/transforms/extractXML.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputXML"/> </map:when> <map:when test="text"> <map:transform src="context://resources/transforms/extractXML.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:transform src="context://resources/transforms/xml2text.xsl" label="text-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputPage"/> </map:when> <map:otherwise> <map:transform src="context://resources/transforms/page2html.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputPage"/> </map:otherwise> </map:select> </map:match>
 
left footerCopyright 2006 – 2010 Hugh Field-Richards. All Rights Reserved.