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

Using Multiple Stylesheets for the Same Content


There are three good methods for using multiple stylesheets for the same content:
 
MethodURLInstructionsDisadvantages
Cocoon Views?cocoon-view=mystylesheetBreakpointsMust reproduce code
Parameter Selector?xsl=mystylesheetSitemaps & QuerystringsMuch code inside pipeline
Usecase?lenya.usecase=xsl&xsl=mystylesheetThis pageExtra files

All three methods work. A Usecase does most of the work in a separate file, so it is the easiest to maintain.

Instructions

This creates a Usecase that allows the doctype to be overridden if the specified XSLT exists, then passes control to the main pipeline, so any customization of the main pipeline is obeyed.

NOTE: {DifferentXSLT} should be replace by your chosen name for the style, and should be all lowercase without braces {}.

1. Add this match to {pub}/publication-sitemap.xmap:
<map:match pattern="*/lenyabody-**">
<map:generate src="cocoon:/lenyabody-{2}" label="xdebug"/>
<map:serialize type="xml" />
</map:match>


2. Add the XSL Usecase.
NEW FILE: {pub}/usecase-xsl.xmap
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:pipelines>
<map:pipeline>
<!-- If the XSLT exists, change the doctype -->
<map:match pattern="**">
<map:act src="xslt/page2xhtml-{request-param:xsl}.xsl" type="resource-exists">
<map:generate src="cocoon://{page-envelope:publication-id}/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{request-param:xsl}{page-envelope:document-id}_{page-envelope:document-language}.html"/>
<map:transform src="../../xslt/util/strip_namespaces.xsl"/>
<map:serialize type="html"/>
</map:act>
<!-- Otherwise use regular doctype -->
<map:generate src="cocoon://{page-envelope:publication-id}/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-id}_{page-envelope:document-language}.html"/>
<map:transform src="../../xslt/util/strip_namespaces.xsl"/>
<map:serialize type="html"/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>


This is meant for multiple versions for display of data, so it only applies to the Live Area, and does not include code from the main entry Pipeine for the "resource-exists" and "language-exists" checks, the authoring GUI, and caching. You can copy the appropriate code from the <map:match pattern="**.html"> Pipeline in publication-sitemap.xmap. As an example, to make it work with the Authoring GUI, add these lines:
<map:match pattern="authoring/**.html">
<map:transform src="cocoon://lenya-page/{page-envelope:publication-id}/authoring/{1}.xml?doctype={page-envelope:document-type}"/>
</map:match>

Just before each of the two lines:
<map:transform src="../../xslt/util/strip_namespaces.xsl"/>


3. Create the new stylesheets:
FILE: {pub}/xslt/page2xhtml-{DifferentXSL}.xsl

This is where you do some work. You should probably start by copying page2xhtml.xsl.

4. Create a translation for each new stylesheet:
FILE: {pub}/xslt/{DifferentXSL}2xhtml.xsl

You can copy homepage2xhtml.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="xhtml2xhtml.xsl"/>
</xsl:stylesheet>

5. To change the xsl, add "&xsl={DifferentXSLT}" to a link. To add the link in your XSLT, use:
<A HREF="{$root}/{$url}?lenya.usecase=xsl&amp;xsl={DifferentXSLT}">
<i18n:text>Change display to {DifferentXSLT}</i18n:text></A>


<< ContentsSitemaps & QueryStrings >>

Contact Solprovider
Paul Ercolino