cst:case

Purpose

One of a number of possible matches which could be selected when processing the cst:switch element.

Please note that only a single attribute from the table following example can be specified on the element.

Contained by

Attribute groups

Attributes

Attribute Description Type Default Options Use
boolean

A boolean value. The client-side value is the equivalent boolean value to that specified here.

xs:boolean     optional 
number

A number value. The client-side value is the equivalent numeric value to that specified here.

xs:number     optional 
string

A string value. The client-side value is the equivalent string value to that specified here.

xs:string     optional 

Example

<?xml version="1.0" encoding="UTF-8"?>
<html
  xmlns="http://www.w3.org/2002/06/xhtml2"
  xmlns:mcs="http://www.volantis.com/xmlns/2006/01/xdime/mcs"
  xmlns:cf2="http://www.volantis.com/xmlns/2009/07/cf2"
  xmlns:ui="http://www.volantis.com/xmlns/2009/07/cf2/ui"
  xmlns:event="http://www.w3.org/2001/xml-events"
  xmlns:template="http://www.volantis.com/xmlns/marlin-template"
  xmlns:cst="http://www.volantis.com/xmlns/2009/07/cf2/template"
  xmlns:json="http://www.volantis.com/xmlns/2009/07/json">
  <head>
    <title>Client Side Template</title>
  </head>
  <body>
    <div>
      <p>Template with switch property containing several slots linked to json
        data</p>
      <cst:template id="t1" data="json1">
        <cst:switch path="datatype">
          <cst:case string="image">
            <cst:a href="href">
              <cst:image path="icon"/>
            </cst:a>
          </cst:case>
          <cst:case string="text">
            <cst:a href="href">
              <cst:value path="name"/>
            </cst:a>
          </cst:case>
          <cst:otherwise style="display: block">
            <span>unknown type '<cst:value path="datatype"/>'</span>
          </cst:otherwise>
        </cst:switch>
      </cst:template>
      <mcs:br/>
      <ui:button id="b1">
        <span>Use first (image) data set</span>
        <cf2:on event="cf2:activate" set="t1#data" component="json1"/>
      </ui:button>
      <ui:button id="b2">
        <span>Use second (text) data set</span>
        <cf2:on event="cf2:activate" set="t1#data" component="json2"/>
      </ui:button>
      <ui:button id="b3">
        <span>Use third (unknown) data set</span>
        <cf2:on event="cf2:activate" set="t1#data" component="json3"/>
      </ui:button>
    </div>
    <div>
      <json:inline id="json1">
        <json:object>
          <json:property name="datatype">
            <json:string>image</json:string>
          </json:property>
          <json:property name="name">
            <json:string>Cow</json:string>
          </json:property>
          <json:property name="icon">
            <json:object>
              <json:property name="src">
                <json:string>assets/images/gallery/photos/img5.jpg</json:string>
              </json:property>
              <json:property name="alt">
                <json:string>Cow alternate text</json:string>
              </json:property>
            </json:object>
          </json:property>
          <json:property name="href">
            <json:string>http://www.google.com/m/search?site=images&amp;q=cow</json:string>
          </json:property>
        </json:object>
      </json:inline>
      <json:inline id="json2">
        <json:object>
          <json:property name="datatype">
            <json:string>text</json:string>
          </json:property>
          <json:property name="name">
            <json:string>Horse</json:string>
          </json:property>
          <json:property name="icon">
            <json:object>
              <json:property name="src">
                <json:string>assets/images/gallery/photos/img4.jpg</json:string>
              </json:property>
              <json:property name="alt">
                <json:string>Horse alternate text</json:string>
              </json:property>
            </json:object>
          </json:property>
          <json:property name="href">
            <json:string>http://www.google.com/m/search?site=images&amp;q=horse</json:string>
          </json:property>
        </json:object>
      </json:inline>
      <json:inline id="json3">
        <json:object>
          <json:property name="datatype">
            <json:string>non-existing-datatype</json:string>
          </json:property>
        </json:object>
      </json:inline>
    </div>
  </body>
</html>

Related topics