Selection elements and attributes

Conditional expressions provide the means for testing values against one another and using markup accordingly. You can use a group of 'select' elements on larger blocks of content, and the related attributes on individual elements. These elements and attributes provide a way to include content that is similar in use to case and switch statements in procedural languages.

Conditional expressions provide the means for testing values against one another and using markup accordingly. You can use a group of 'select' elements on larger blocks of content, and the related attributes on individual elements. These elements and attributes provide a way to include content that is similar in use to case and switch statements in procedural languages.

Select elements

The sel:select element is a container for one or more sel:when elements and an optional sel:otherwise element. The expr attributes on the sel:select and sel:when elements control the conditions for processing.

The sel:select has an additional precept attribute. There are two possible values; 'matchfirst' (default) determines that only the first selected sel:when element is processed, while 'matchevery' means that all the selected sel:when elements are handled. The content of the sel:otherwise element is only processed if no sel:when elements are selected.

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
  xmlns:sel="http://www.w3.org/2004/06/diselect">
  <head>
    <title>sel:select</title>
  </head>
  <body>
    <sel:select>
      <sel:when expr="device:policy-value('supports.client.framework')='true'">
        <p>This device supports the Client Framework 1.</p>
      </sel:when>
      <sel:otherwise>
        <p>This device does not support the Client Framework 1.</p>
      </sel:otherwise>
    </sel:select>
  </body>
</html>

You can use the sel:if element as an alternative to use of the sel:expr attribute when a condition applies to several elements. It is also useful in applying control to a fragment of a document that does not have a single root element.

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
  xmlns:sel="http://www.w3.org/2004/06/diselect">
  <head>
    <title>sel:if</title>
  </head>
  <body>
    <sel:if expr="device:policy-value('supports.client.framework')='true'">
      <p>This device supports the Client Framework 1.</p>
    </sel:if>
    <sel:if expr="device:policy-value('supports.client.framework')='false'">
      <p>This device does not support the Client Framework 1.</p>
    </sel:if>
  </body>
</html>
Note:

There is no sel:else element. Use sel:select element and its children to handle alternative versions of your content.

Using selection attributes

If you use selection attributes on elements outside the sel: namespace, they must be qualified with the namespace prefix.

The sel:expr attribute contains a conditional expression that determines whether or not an element is selected for processing. If the result of the evaluate is 'true' (default), the element is selected, otherwise the element and its children are skipped. So if you omit this attribute from an element, it will always be selected.

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
  xmlns:sel="http://www.w3.org/2004/06/diselect">
  <head>
    <title>sel:expr</title>
  </head>
  <body>
    <p sel:expr="device:policy-value('supports.client.framework')='true'">
      This device supports the Client Framework 1.</p>
    <p sel:expr="device:policy-value('supports.client.framework')='false'">
      This device does not support the Client Framework 1.</p>
  </body>
</html>

The sel:selid attribute can be used to substitute an identifier in source content with another rendered in the output. If you wish to maintain alternate versions of elements to be used under different circumstances, substitution can help avoid clashes of id attribute in both the source and the output. You can also reliably link to targets using consistent identifiers.

During processing, the sel:selid attribute is replaced with an id attribute with the same value.

Related topics