Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Docs MVC XSL VariantSupport

Frank Kleine edited this page Apr 7, 2012 · 1 revision

Table of Contents

Variant support

The XML/XSL view engine supports variants. For the concept of variants and how to manage them see please refer to testing customer experience with variants. This chapter describes how to check the current variant of the request and to display contents based on variants with the XML/XSL view engine.

For all following examples we suppose the following variants are configured:

#xml
<?xml version="1.0" encoding="iso-8859-1"?>
<xj:configuration
    xmlns:xj="http://xjconf.net/XJConf"
    xmlns="http://stubbles.net/websites/variantmanager">
  <variants name="default">
    <requestParam name="request" title="request" paramName="var" />
    <random name="random1" title="random1" weight="1">
      <lead name="lead" title="lead" />
    </random>
    <random name="random2" title="random2" weight="2" />
  </variants>
</xj:configuration>

Enabling variant support

To make use of the variant support it must be enabled. This is simply done by adding a namespace to the stylesheet which should use variants:

#xml
<?xml version="1.0" encoding="utf-8"?>
<parts
    xmlns:stub="http://stubbles.net/stub"
    xmlns:variant="http://stubbles.net/variant"
    xmlns:ixsl="http://www.w3.org/1999/XSL/Transform">
<!-- contents here --/>
</parts>

Name of current variant

To get the name of the current variant use <variant:get-current/> This will display the name of the current selected variant. Sometimes it may be necessary to display just the basename of the variant: <variant:get-current-base/>. To make use of this the variant parts have to be separated by a colon.

Restrict to a certain variant

To display some contents only within a certain variant the <variant:restrict-to/> template may be used. It supports five different attributes of which only one must be used:

<variant:restrict-to variant="request">
  This text is only displayed in variant <em>request</em>.<br /><br />
</variant:restrict-to>
<variant:restrict-to base="random1">
  This text is only displayed in variant <em>random1</em>.<br /><br />
</variant:restrict-to>
<variant:restrict-to end="lead">
  This text is only displayed in variant <em>random1:lead</em>.<br /><br />
</variant:restrict-to>
<variant:restrict-to start="random">
  This text is only displayed in variants <em>random1</em> and <em>random2</em>.<br /><br />
</variant:restrict-to>
<variant:restrict-to alias="preferred">
  This text is only displayed in variant <em>random2</em><br /><br />
</variant:restrict-to>

Exclude a certain variant

The opposite of the restriction is to exclude variants with <variant:except variant="request"/>. It supports the same five attributes as restriction:

<variant:except variant="request">
  This text is displayed in every variant except <em>request</em>.<br /><br />
</variant:except>
<variant:except base="random1">
  This text is displayed in every variant except <em>random1</em>.<br /><br />
</variant:except>
<variant:except end="lead">
  This text is displayed in every variant except <em>random1:lead</em>.<br /><br />
</variant:except>
<variant:except start="random">
  This text is displayed in every variant except <em>random1</em> and <em>random2</em>.<br /><br />
</variant:except>
<variant:except alias="preferred">
  This text is displayed in every variant except <em>random2</em>.<br /><br />
</variant:except>

Choose a certain variant

Most times it becomes necessary to display contents depending on the variant, e.g. different prices in different variants. This can be achieved by using the <variant:choose> template:

<variant:choose>
  <variant:when variant="request">
    This text is only displayed in variant <em>request</em>.<br /><br />
  </variant:when>
  <variant:when end="lead">
    This text is only displayed in variant <em>random1:lead</em>.<br /><br />
  </variant:when>
  <variant:otherwise>
    This text is displayed in every other variant.<br /><br />
  </variant:otherwise>
</variant:choose>

The templates supports the same five attributes as in except and restrict-to.

Clone this wiki locally