Copyright © 2007 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This document specifies a syntax and processing model for general purpose content selection or filtering. Selection involves conditional processing of various parts of an XML information set according to the results of the evaluation of expressions. Using this mechanism some parts of the information set can be selected for further processing and others can be suppressed. The specification of the parts of the infoset affected and the expressions that govern processing is by means of XML-friendly syntax. This includes elements, attributes and XPath expressions. This document specifies how these components work together to provide general purpose selection.
There is a companion document which provides introductory information concerned with this specification [DI Primer].
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This July 2007 publication is a Candidate Recommendation; it has been widely reviewed and satisfies the requirements defined in the charter of the Ubiquitous Web Application Working Group and also identified in the Authoring Challenges for Device Independence document; W3C publishes a Candidate Recommendation to gather implementation experience.
The first release of this document was 11 June 2004 and the Ubiquitous Web Application Working Group has made its best effort to address the comments received during the first Last Call Working Draft, and those received during the second Last Call Working Draft. The change log enumerates changes since the 10 October 2006 Working Draft. The design has stabilized and the Working Group intends to advance this specification to Proposed Recommendation once the exit criteria below are met:
This specification will remain a Candidate Recommendation until at least 31 October 2007.
Comments on this document should be sent to public-diselect-editors@w3.org.This list is archived at http://lists.w3.org/Archives/Public/public-diselect-editors/.
Publication as a Candidate Recommendation does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document is published as part of the W3C Ubiquitous Web Applications Activity by the Ubiquitous Web Application Working Group . It is a deliverable as defined in the Charter of that group.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
1 Introduction
1.1 Conformance Information for
DISelect
1.1.1 Normative and Informative
Information
1.1.2 Normative Language for
Conformance Requirements
1.1.3 DISelect Profiles
1.1.4 Document Conformance
1.1.5 DISelect Implementation
Conformance
1.2 Documentation Conventions
2 Document Structure
2.1 The Namespaces
2.2 The Selection Module
3 Processing Model
3.1 Events Overview
3.2 Events in Response to Errors
3.2.1 The
diselect-invalid-type-error Event
3.2.2 The
diselect-redeclaration-error Event
3.2.3 The
diselect-declaration-exception Event
3.2.4 The
diselect-compute-exception Event
4 Attributes for Conditional
Processing
4.1 Overview
4.2 The expr Attribute in Host
Language Elements
4.3 The selid and selidname
Attributes
4.3.1 Generated Host Language
Identifiers
4.4 The functions
Attribute
4.5 Using the Attributes
5 Elements for Conditional
Processing
5.1 Overview
5.2 Conditional Processing
5.2.1 The if Element
5.2.1.1 Attributes
5.2.2 The select
Element
5.2.2.1 Attributes
5.2.2.2 Processing
5.2.3 The when Element
5.2.3.1 Attributes
5.2.4 The otherwise
Element
5.2.4.1 Attributes
5.3 Using the Elements
6 Variables
6.1 The variable Element
6.1.1 Attributes
6.1.2 Declaring a Variable
6.1.3 Referencing an Existing
Variable Using the variable Element
6.1.4 References to Variables in
XPath Expressions
6.1.5 Scope of Variables and
Nesting
6.1.6 Types
6.1.6.1 Type
Conversion
6.2 The value Element
6.2.1 Attributes
6.3 Using Variables
7 Attribute Value Templates
7.1 Using Attribute Value Templates
8 XPath Expressions
8.1 Identifying Profiles and
Versions
8.1.1 The getProfileName
function
8.1.1.1 Prototype
8.1.1.2 Function
8.1.2 The sel:getVersion
function
8.1.2.1 Prototype
8.1.2.2 Function
8.2 DISelect Basic XPath
Support
8.2.1 Accessing the Delivery
Context using the XPath Subset
8.2.2 Formal Grammar for the
DISelect Basic Subset
8.3 DISelect Full XPath
Support
8.3.1 Path-Based Access to the
Delivery Context
8.3.2 Path-Based Access to the
Host Document
8.4 Extension Functions
A Schema
B References
B.1 Normative References
B.2 Informative References
C Changes in this Version
(Non-Normative)
D Acknowledgements (Non-Normative)
The module described in this specification provides the ability to select between different versions of materials. The module is designed to be used within other markup languages, and in particular, within the device independent authoring language profile [DIAL] being developed by DIWG. The term host language is used in this document to indicate the language within which DISelect is being used.
In its paper on Authoring Challenges [Authoring Challenges], DIWG identified a series of challenges faced by authors trying to create materials that could be used on a wide variety of devices with very different characteristics. One common theme emerging from this work was the need to support authors in the specification of variabilityin the materials they produce.
In its paper on Device Independence Principles [DI Principles], DIWG pointed out that the process by which authored materials are adapted for use on particular devices may take place at any point between the source of the material and the device itself.
The ability to select between different versions of material provides one important mechanism by which authors can support variability. The mechanism by which a particular version is chosen from those available, during adaptation should not be excessive in its processing demands, since it may need to be performed on a device with limited capacity.
Some user agents provide programming capability that can be exploited by authors to achieve results similar to those described in this specification. For example, [ECMAScript] is available in some browsers. Such facilities are, of course, very powerful, and allow dynamic modification of and interaction with the page during the user interaction. However, they are not universally available. In addition, the intent of the author is embodied within the program code rather than being declared within markup. This may cause difficulties in interpretation for assistive technologies, for example. A recent TAG Finding [Least Power] encourages the use of the least powerful language which is suitable for a particular purpose. The definition of this module attempts to follow this principle.
This specification provides a mechanism for the selection of the content that is to be expressed when adaptation takes place. It does not attempt to provide the dynamic modification associated with browser programming, embodied in languages such as [ECMAScript], nor does it attempt to provide the comprehensive transformation capabilities of [XSLT]. Rather, it provides capabilities that could be implemented using those mechanisms, but in a way that can requires only modest capability from the processors involved.
The normative and informative parts of this specification are identified by use of labels within various sections. Generally, everything in the specification is considered to be normative, apart from the examples.
Individual conformance requirements or testable statements are identified in the DISelect specification by the use of specific key words. In particular, the key words must, must not, required, shall, shall not, should, should not, recommended, may, and optionalin this specification are to be interpreted as described in [IETF RFC 2119].
This specification defines two profiles of the DISelect markup:
This profile contains all the markup normatively defined in this specification.
This profile contains all the markup normatively defined in this specification, with the exception of the markup labelled as belonging only to the DISelect Full profile
This profile is a subset of the DISelect Full profile intended to be implemented on small-footprint DISelect implementations, typically running on portable devices with limited processing power and memory.
A Document conforming to the DISelect Full profile may include any markup defined in this document.
A Document conforming to the DISelect Basic profile must not include markup defined in this document as belonging only to the DISelect Full profile.
A conformant implementation of this specification results in a DISelect processor. Such a processor must conform to the processing model described in 3 Processing Model.
A conformant DISelect processor may reside anywhere convenient within any component that participates in the delivery of material to a Web client. In particular, implementations may be placed within origin servers, in intermediaries, such as proxies, or on the client itself.
A processor that supports the DISelect Full profile must implement all the normative features defined in this specification.
A processor that supports the DISelect Basic profile must implement the normative features defined in this specification which are not described as belonging to the DISelect Full profile. A DISelect Basic processor encountering features belonging only to the DISelect Full profile must raise a diselect-compute-exception exception.
The XML representations of various elements within DISelect are presented using the syntax for Abstract Modules in XHTML Modularization [XHTML Modularization]
The following namespace prefixes and corresponding namespace identifiers are used in this document:
The DISelect namespace described in section 2.1 The Namespaces.
The Delivery Context namespace described in section 2.1 The Namespaces.
In the examples, the default namespace, with no prefix, is used to
indicate the host language within which the
content selection markup is being used. The examples assume that the host
language is XHTML Version 2 [XHTML 2]. The examples
also assume that the integration with the host language makes the assumption
that where the expr
attribute is not explicitly referenced, its
value is assumed to be true
. In other words, host language
elements carrying no expr
attribute are unaffected by the
presence of DISelect. The same assumption applies to select
elements that do not explicitly carry an expr
attribute.
Expressions in the examples used in this document are based on [XPath 1.0]. This syntax requires that certain special characters be escaped appropriately for use within XML processors. This quoting is used explicitly throughout the document.
DISelect is not a stand-alone document type. It is intended to be integrated into other host languages such as XHTML. Such integration could result in the elements and attributes described in this specification being subsumed into the host language namespace. Alternatively, it might result in the elements and attributes being added to a host language, but in a separate namespace. The DISelect namespace is provided for this purpose.
The DISelect namespace has the URI:
http://www.w3.org/2005/sel
.
The Delivery Context namespace has the URI:
http://www.w3.org/2005/dcn
.
Elements | Attributes | Minimal Content Model |
---|---|---|
ANY ##other | expr | |
ANY ##other | selid | |
ANY ##other | selidname | |
ANY ##other | functions | |
if | expr, selidname, functions | ((ANY ##other) | if | select)* |
select | expr, precept, selidname, functions | when* otherwise? |
when | expr, selidname, functions | ((ANY ##other) | if | select)* |
otherwise | selidname, functions | ((ANY ##other) | if | select)* |
variable | name, ref, value | EMPTY |
value | expr |
The selection module consists of a set of elements and associated attributes that allow authors to specify how content will be selected for use in different delivery contexts.
The if and select elements provide mechanisms for choosing whether or not to use particular parts of the content. Their associated attributes and sub-elements provide the means to control how the alternatives are defined and how the decisions are made.
Section 4 Attributes for Conditional Processing describes how the attributes are used within a host markup language. Section 5 Elements for Conditional Processing describes the markup elements themselves. Section 6 Variables describes variables that can be used to simplify expressions. Section 7 Attribute Value Templates describes how DISelect supports the use of attribute value templates in host language elements. Finally, section 8 XPath Expressions describes the expressions used within DISelect to control the decisions about which content is used.
This section is normative.
Selection, as defined in this document, is a specific type of transformation applied to an XML information set [XML Infoset]. The input for the selection transformation is referred to as the source infoset. The result of the transformation is referred to as the result infoset.
The source infoset includes elements and attributes from the DISelect namespace. These attributes and elements control whether or not certain parts of the source infoset are expressed in the result infoset. The details of how the attributes and elements control selection are described in 4 Attributes for Conditional Processing and 5 Elements for Conditional Processing.
The elements and attributes from the DISelect namespace which are present in the source infoset do not themselves appear in the result infoset.
DISelect uses the events system defined in [DOM2 Events] and [XML Events]. These event models specify an event capture flow that includes:
Processing where the event flows down the DOM tree towards its target element. In this phase, appropriately registered event handlers are notified of the event and may perform processing based on it.
When the event arrives at its target element, event handlers registered there are notified of the event and may perform processing based on it.
Processing in which the event flows back up the DOM tree towards its root. In this phase, appropriately registered event handlers are notified of the event an may perform processing based on it.
The following sections define specific events associated with DISelect. In each case, the target element is defined together with information about whether the event bubbles and whether or not the default action can be cancelled.
During transformation, certain situations may occur that cause events to be raised. These situations represent errors that have been detected by the DISelect processor. DISelect does not contain any facilities by which events can be detected and processed other than by the processor.
Error indications happen as a result of unusual conditions in the DISelect Processor. There are two types of error indication.
Exceptions cause the DISelect processor to halt. The names bear the suffix exception.
Errors are raised for notification. They do not cause the DISelect processor to halt. They bear the suffix error. It is permissible for the DISelect Processor to perform default handling for any of the events of this type. For example, a DISelect processor might choose to log error messages to a file.
diselect-invalid-type-error
EventThis event is raised when the DISelect processor detects a type mismatch. For example, this event will be raised if an attempt is made to assign a value to a variable which cannot be converted to the variable's type.
Cancelable? | Bubbles? | Target Element | Default Action |
---|---|---|---|
No | Yes | The element in which the type mismatch occurred | The DISelect processor ignores the assignment. |
diselect-redeclaration-error
EventThis event is raised when an attempt is made to declare a variable that is already in existence. It is an error.
Cancelable? | Bubbles? | Target Element | Default Action |
---|---|---|---|
No | Yes | The element in which the redeclaration occurred | The DISelect processor ignores the redeclaration. |
diselect-declaration-exception
EventThis event is raised when an attempt is made to declare a variable but the declaration is invalid. A declaration is invalid, for example, if no initial value is specified for the variable. It is an exception.
Cancelable? | Bubbles? | Target Element | Default Action |
---|---|---|---|
No | Yes | The element in which the declaration occurred | The DISelect processor halts. |
diselect-compute-exception
EventThis event is raised when an exception occurs during the evaluation of an XPath expression. It is raised, for example, if an XPath function required for evaluation of an expression is not available to the processor. It is also raised if a DISelect Basic processor encounters an expression only defined in the DISelect Full profile. It is an exception.
This exception should not be used to detect which DISelect
profile is supported by a processor. Instead, a document author
should use the getProfileName
or
getVersion
functions. See 8.1 Identifying Profiles and
Versions
Cancelable? | Bubbles? | Target Element | Default Action |
---|---|---|---|
No | Yes | The element in which the compute exception occurred | The DISelect processor halts. |
This section is normative.
DISelect provides three attributes that can be used with elements of the
host language. This section describes those attributes. One attribute,
expr
, simplifies the specification of selection under certain
circumstances. The other attributes, selid
and
selidname
, provide a mechanism for avoiding problems associated
with duplication of values of host language attributes that represent unique
identifiers.
When used within a host language element, the DISelect attributes need to be appropriately qualified to indicate that they are within the content selection namespace.
expr
Attribute in Host
Language ElementsThe expr
attribute is useful for simple decisions that affect
small amounts of content. It is used within elements of the host language. It
defines an expression used to determine
whether or not the host language element appears in the result infoset. It
can be added to any element of the host language.
The DISelect processor evaluates the expression defined by the
expr
attribute. If the result is a boolean
value of true
, the
element that contains the attribute and all its descendants appear in the
result infoset. The expr
attribute itself does not appear in the
result infoset. If the expression has a value of false
, the
element and all its descendents are omitted from the result infoset.
The expressions used with this attribute are described in section 8 XPath Expressions.
Section 4.5 Using the Attributes
illustrates the use of the expr
attribute.
If the decision to include or exclude material applies to a significant amount of content or if a number of different versions of the content are available, it is usually simpler to use the elements which are also part of this module. These are described in section 5 Elements for Conditional Processing.
selid
and
selidname
AttributesThe notion of unique identifiers that can be associated with particular
elements in markup languages is common, if not universal. Using them allows
particular instances to be identified so that, for example, links can be
created or particular styling can be specified. Often, markup languages use
an attribute named id
for this identifier. Markup languages
based on XML often use the attribute xml:id
for this purpose.
The uniqueness of these identifiers usually forms part of the validity constraints associated with the host language. The presence of multiple elements with the same identifier violates the constraints and makes the associated document invalid. This is a potential issue when the host language is combined with a selection mechanism, such as the one detailed here. An author may wish to provide alternative versions of particular elements to be used under different circumstances. Both versions may need to carry the same identifier. Consequently, although the document resulting from processing the selection markup will be valid, the document containing the selection markup is not.
The selid
and selidname
attributes provide a
solution for this problem. Rather than specify the host language unique
identifier attribute directly, authors can use the DISelect
selid
and selidname
attributes instead. The
selid
attribute defines the value of a host language identifier
while the selidname
attribute defines its name.
By default, a DISelect processor uses the value of the selid
attribute to generate an xml:id
attribute. During processing,
the value of selid
attribute on an element of in the source
infoset becomes the value of the generated xml:id
attribute on
the equivalent element of the result infoset.
If the host language uses an attribute other than xml:id
as
its unique identifier, the attribute generated can be named using the
selidname
attribute. The value of the selidname
attribute is the name of the host language attribute which represents a
unique identifier. When selidname
is used, the DISelect
processor generates unique identifiers with the specified name, rather than
xml:id
. The scope of the selidname
attribute is the
host language element on which it is used and all descendent elements.
Consequently, if it is specified on the root element of the host document, it
can be made to apply to the entire document.
Section 4.5 Using the Attributes
illustrates the use of the selid
and selidname
attributes.
functions
AttributeThis attribute defines the names of additional XPath functions that are required to enable processing of material that contains DISelect elements and attributes. It allows authors to verify that the materials they have provided can be processed by the DISelect processor. The names in the list reference functions that are required by the content in addition to the set provided by the DISelect processor itself. Facilities that must be provided by the DISelect processor are described in section 8 XPath Expressions.
The value of the functions
attribute is a space-separated list
of the XPath extension functions that are required for processing. Each
extension function is represented by a QName.
The DISelect processor verifies that any functions specified using this element are available. If they are not, the processor causes an invalid computation exception to be raised (see 3.2.4 The diselect-compute-exception Event).
A DISelect processor mustverify the availability of the
resources defined by this attribute no later than the point during processing
at which it encounters the functions
attribute in the source
infoset. A DISelect processor mayverify resource
availability before it encounters the attribute. For example, the processor
may verify the availability of resources at the time the infoset containing
the attribute is loaded. This provides an optimization by avoiding
unnecessary processing that would be rendered invalid by subsequent discovery
of missing resources.
The functions
attribute can occur any number of times within
a source infoset. The set of resources required by the source infoset is
considered to be the union of those defined by all of the
functions
attributes that are processed by the DISelect
processor.
The examples in this section are informative. They have been chosen for clarity and simplicity. They are not intended to represent best practice. The companion primer [DI Primer] discusses a variety of ways to use DISelect under different circumstances.
The following example illustrates suppression of the display of an image
if the usable width of the display on a device is too small. The first and
third paragraphs containing the text are always presented. However, the
second paragraph containing the image is shown only if the dcn:cssmq-width
function indicates that the usable width of the device display is more than
200 pixels. If the second paragraph is shown, the object
element
will carry a generated xml:id
attribute with a value of
artimg42
.
<p>The flooding was quite extensive.</p> <p sel:expr="dcn:cssmq-width('px') > 200"> <object src="image1" sel:selid="artimg42"/> </p> <p>Many people were evacuated from their homes.</p>
The conditional expressions used within the
expr
attribute can contain multiple terms that relate to
different characteristics from the delivery context. So, for example, if the
image should only be shown on devices with color displays wider than 200
pixels, the following markup might be used.
<p>The flooding was quite extensive.</p> <p sel:expr="dcn:cssmq-width('px') > 200 and dcn:cssmq-color() > 0"> <object src="image1" sel:selid="artimg42" sel:selidname="myns:myid"/> </p> <p>Many people were evacuated from their homes.</p>
In this version of the example, the value of the expr
attribute is true only if the dcn:cssmq-width
function indicates that the usable width of the device is more than 200
pixels and that the dcn:cssmq-color
function indicates that the display supports color.
In addition, in this second example, if the second paragraph is shown, the
object
element will carry a generated myns:myid
attribute with a value of artimg42
. In this case, the
selid
attribute specifies the value of the generated attribute
and the selidname
attribute specifies its name.
<div selidname="myns:myid"> <p>The flooding was quite extensive.</p> <p sel:expr="dcn:cssmq-width('px') > 200 and dcn:cssmq-color() > 0"> <object src="image1" sel:selid="artimg42"/> </p> <p>Many people were evacuated from their homes.</p> </div>
This version of the example is the same as the previous one, except that
the selidname
attribute is used to specify the name of the
attribute to be generated from any sel:selid
attributes in the
markup contained within the div
element.
Notice that in these examples, the attributes relating to conditional selection are qualified to indicate that they are from the DISelect namespace.
This section is normative.
DISelect defines several elements used for controlling whether or not material appears in the result infoset as a result of processing.
if
ElementThis element defines a set of material that is to be included in the
result infoset if the associated expression has the appropriate value. This
element provides an alternative to use of the expr
attribute in the elements of
the host language. It is particularly useful when a specific condition
applies to several elements of the host language. In addition, the
if
element allows control to be applied to a wider range of XML
document fragments than does the expr
attribute alone.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
Note that there is no else
element. Instead, the select
element and its children,
provide the mechanism for choosing between alternative versions of
material.
This mandatory attribute defines an expression used in determining whether or
not the descendents of the element appear in the result infoset. If the
expression evaluates to a boolean
value of true
, the
descendents of the if
element appear in the result
infoset. If the expression evaluates to a value of false
,
the descendents of the if
element are omitted from the
result infoset.
This optional attribute defines the name of the host language
attribute that provides unique identifiers. If it is not specified on
this element, and has not been specified on any antecedent element, the
DISelect processor assumes that the host language unique identifiers
are specified using the xml:id
attribute. Section 4.3 The selid and selidname
Attributes contains more details on the use of attributes
associated with host language identifiers.
This optional attribute defines the names of additional XPath functions that are required to enable processing of material within the element on which it is used. The value of the attribute is a space-separated list of the XPath extension functions (represented by QNames) that are required for processing. Section 4.4 The functions Attribute contains more details on the use of this attribute.
select
ElementThis element encloses one or more sets of material that are subject to
conditional selection. It contains one or more when
elements and
an optional otherwise
element. Expressions associated with the
select
and when
elements control the conditions
under which particular parts of the content are processed.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
This optional attribute defines an expression used in determining whether or
not the entire select
element is processed by the DISelect
processor. If the expression evaluates to a boolean
value of true
, the
select
element is processed with the result that some of
the content it contains may appear in the result infoset. If the
expression has a value of false
, the entire
select
element is ignored by the DISelect processor.
This optional attribute defines the basic rule applied to matching
within the select
element. It can take one of the
following values:
matchfirst
This is the default value. When it is specified, the descendents of
the first when
element that has an expr
attribute that evaluates to true
appear in the result
infoset. The descendents of other when
elements are
ignored, even if their expr
attributes evaluate to
true
. The descendents of any otherwise
element are ignored if any of the when
elements has an
expr
attribute that evaluates to true
.
matchevery
When this value is specified, the descendents of every
when
element that has an expr
attribute that
evaluates to true
appear in the result infoset. The
descendents of any otherwise
element are ignored if any of
the when
elements has an expr
attribute that
evaluates to true
.
This optional attribute defines the name of the host language
attribute that provides unique identifiers. If it is not specified on
this element, and has not been specified on any antecedent element, the
DISelect processor assumes that the host language unique identifiers
are specified using the xml:id
attribute. Section 4.3 The selid and selidname
Attributes contains more details on the use of attributes
associated with host language identifiers.
This optional attribute defines the names of additional XPath functions that are required to enable processing of material within the element on which it is used. The value of the attribute is a space-separated list of the XPath extension functions (represented by QNames) that are required for processing. Section 4.4 The functions Attribute contains more details on the use of this attribute.
The when
elements within a select
are processed
in document order. This is significant since this order can affect the
particular when
element chosen when the precept
attribute has a value of matchfirst
. It also affects the order
in which material is included in the result infoset when the
precept
attribute is set to matchevery
and multiple
when
elements have expr
attributes that evaluate to
true
.
when
ElementThis element defines a set of material that is to be selected for
processing if the associated expression has the appropriate value. A single
select
element may contain multiple when
elements.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
This mandatory attribute defines an expression used in determining whether or
not the descendents of the element appear in the result infoset. If the
expression evaluates to a boolean
value of true
, the
descendents of the when
element appear in the result
infoset. If it evaluates to false
, the descendents of the
when
element are omitted from the result infoset. Note,
however, that the value of the precept
attribute of the
containing select
element determines overall which
when
elements are considered for possible selection.
This optional attribute defines the name of the host language
attribute that provides unique identifiers. If it is not specified on
this element, and has not been specified on any antecedent element, the
DISelect processor assumes that the host language unique identifiers
are specified using the xml:id
attribute. Section 4.3 The selid and selidname
Attributes contains more details on the use of attributes
associated with host language identifiers.
This optional attribute defines the names of additional XPath functions that are required to enable processing of material within the element on which it is used. The value of the attribute is a space-separated list of the XPath extension functions (represented by QNames) that are required for processing. Section 4.4 The functions Attribute contains more details on the use of this attribute.
otherwise
ElementThis element defines a set of material that appears in the result infoset
if none of the when
elements within the containing
select
element has an expr
attribute that evaluates
to true
.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
This optional attribute defines the name of the host language
attribute that provides unique identifiers. If it is omitted, the
DISelect processor assumes that the host language unique identifier is
xml:id
. Section 4.3
The selid and selidname Attributes contains more details on the
use of attributes associated with host language identifiers.
This optional attribute defines the names of additional XPath functions that are required to enable processing of material within the element on which it is used. The value of the attribute is a space-separated list of the XPath extension functions (represented by QNames that are required for processing. Section 4.4 The functions Attribute contains more details on the use of this attribute.
The examples in this section are informative. They have been chosen for clarity and simplicity. They are not intended to represent best practice. The companion primer [DI Primer] discusses a variety of ways to use DISelect under different circumstances.
In this first example, the expr
attribute on the
if
element controls the selection. If the display on the device
is more than 200 pixels wide, both the image and the paragraph will be
included in the result infoset. If the display is not more than 200 pixels
wide, they will be omitted.
<sel:if expr="dcn:cssmq-width('px') > 200"> <object src="image1"/> <p>Many people had to be evacuated.</p> </sel:if>
In the second example, the expr
attributes on the
when
elements control the selection.
<sel:select> <sel:when expr="dcn:cssmq-width('px') > 200"> <object sel:selid="pic42" src="image1"/> </sel:when> <sel:when expr="dcn:cssmq-color() > 4"> <object sel:selid="pic42" src="image2"/> </sel:when> <sel:otherwise> <p sel:selid="pic42">Many people had to be evacuated.</p> </sel:otherwise> </sel:select>
Each when
element carries an expression in its
expr
attribute. The select
element does not have a
precept
attribute. As a result, the precept defaults to
matchfirst
. Consequently, the descendents of the first
when
element whose expr
attribute evaluates to
true
will be included in the result infoset. Based on the
expressions in the example, if the usable width of the device, as reported by
the dcn:cssmq-width
function, is greater than 200 pixels, image1
will be included.
If it is not, but if the device supports more than 4 bits per color, as
reported by the dcn:cssmq-color
function, image2
will be included. If neither of these
conditions is true the paragraph of text is included.
This example also illustrates use of the selid
attribute. The image
elements and the paragraph element all carry the same value of
pic42
for this attribute. After processing, whichever of the
elements appears in the result infoset will carry an id
attribute with this value.
<sel:select precept="matchevery"> <sel:when expr="dcn:cssmq-width('px') > 200"> <object src="image1"/> </sel:when> <sel:when expr="dcn:cssmq-color() > 4"> <object src="image2"/> </sel:when> <sel:otherwise> <p>Many people had to be evacuated.</p> </sel:otherwise> </sel:select>
The third example is a slightly modified version of the second example.
The select
element carries a precept
attribute with
a value of matchevery
. This change means that the descendents of
every when
element whose expr
attribute evaluates
to true
are included in the result infoset. In this version of
the example, if the usable width of the device is greater than 200 pixels and
the device supports more than 4 bits per color, both images will be included.
With a precept of matchfirst
, only image1
would
have been included. If neither of the conditions is true, the paragraph be
included instead of the images.
<div sel:selidname="myns:myid" sel:functions="myfns:specialFunction1 mynfs:specialFunction2"> ... <sel:select precept="matchfirst"> <sel:when expr="dcn:cssmq-width('px') < 200 and dcn:cssmq-color() > 4"> <object src="smallimage"/> </sel:when> <sel:when expr="dcn:cssmq-color() > 4"> <object src="biggerimage"/> </sel:when> <sel:otherwise> <p>Many people had to be evacuated.</p> </sel:otherwise> </sel:select> ... </div>
The final example illustrates the use of slightly more complex expressions within the expr
attribute on the when
elements. In this case, the content of the
first when
element will be selected if the usable width of the
device is less than 200 pixels and the device supports more than 4 bits per
color. Notice the need to use the entity <
to specify the
comparison "less than". The "<" character is special and needs to be
escaped this way in XPath expressions used within XML documents.
In addition, this example illustrates use of the selidname
attribute on the containing host language div
element. This
attribute defines the name of the generated unique identifiers as
myns:myid. The same div
element also includes a
functions
attribute that defines two additional functions needed
within this particular source infoset.
DISelect supports the use of variables to help reduce the complexity of expressions and markup. Variables are declared and initialized using markup. Their values can also be modified using markup. Variables can be referenced from within expressions using standard XPath mechanisms.
variable
ElementThe variable
element is used to declare a variable and to set
its value.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
This attribute specifies the name of the variable. It is used when declaring a new variable.
This attribute specifies the name of the variable. It is used when referring to a variable that has already been declared.
This attribute specifies an XPath expression that provides the value to be assigned to the variable.
A variable is declared by using the variable
element with its
name
attribute set to the name of the new variable. Variables
must be declared before they can be referenced.
The initial value of a variable is used to determine its type. The type of the variable is the type of the result of the expression that provides its initial value.
It is mandatory, to supply an initial value to a variable when declaring
it. Initial values are supplied using a suitable expression in the
value
attribute. If the initial value is omitted from a
declaration, an invalid declaration exception is raised (see
3.2.3 The
diselect-declaration-exception Event). The DISelect processor
halts.
References to existing variables from markup use the variable
element and specify the name of the variable through the ref
attribute. The value of a variable can be altered using this form of
reference.
When a variable is updated, the supplied value is converted to the type associated with the variable when it was originally declared. If conversion fails, an invalid type event is raised (see 3.2.1 The diselect-invalid-type-error Event). The DISelect processor continues processing, but the value of the variable remains unchanged.
References from XPath expressions use the normal notation. The name of the
variable is prefixed with $. Consequently, a variable
declared using a variable
element with a name
attribute of width
is referenced from an XPath expression as
$width
.
The declaration of a variable defines its scope. The scope of a variable is from the point within its parent element at which it is declared, to the end of the parent element. Repeated declaration of a variable within the same scope causes a redeclarationevent to be raised (see 3.2.2 The diselect-redeclaration-error Event). This is an error. The DISelect processor continues processing, but ignores the redeclaration.
A variable can be referenced only from within its scope. An element can reference a variable if it is within the scope of the variable. An expression can reference a variable if it is associated with an element that is within the scope of the variable.
If variables with the same name are declared in nested scopes, the inner declaration hides the outer declaration for the scope of the inner declaration. References to the variable from within the inner scope apply to the inner declaration.
Variables in DISelect are typed. The following datatypes are recognized by DISelect processors:
This is the string data type as defined in [XPath 1.0]
This is the number data type as defined in [XPath 1.0]
This is the boolean data type as defined in [XPath 1.0]
When the value being assigned to a variable differs in type from the type associated with the variable itself, conversion is required. The rules that apply to conversion in DISelect are the same as those described in XPath [XPath 1.0].
If conversion fails, a diselect-invalid-type-error event is raised. This is an error. The DISelect processor continues processing, but ignores the assignment.
value
ElementThe value
element is used to include the value of an
expression in the content. The DISelect processor evaluates the expression
specified in the element. It places the value of that expression in the
result infoset in place of the value
element.
As described in 3 Processing Model, neither the element itself nor any of its attributes appears in the result infoset.
This mandatory attribute defines the expression that is evaluated to compute the value to be inserted into the result infoset in place of the element.
The examples in this section are informative. They have been chosen for clarity and simplicity. They are not intended to represent best practice. The companion primer [DI Primer] discusses a variety of ways to use DISelect under different circumstances.
<sel:variable name="nColors" value="dcn:cssmq-color(0)"/> <sel:if expr="$nColors > 0"> <p>Your device can display <sel:value expr="$nColors"/> different colors.</p> </sel:if>
In this example, variable nColors
is set by a call to the
function dcn:cssmq-color
.
This function returns the number of colors supported by the device. The
variable is referenced within the expression in the
expr
attribute of the if
element. If the value of the
variable is greater than zero, indicating that the device supports color, the
paragraph is included in the result infoset. The value of the
nColors
variable appears in place of the sel:value
element within the paragraph.
This section is normative. It applies only to the full profile of DISelect.
The concept of Attribute Value Templates (AVTs) is taken from XSLT [XSLT]. Support for AVTs is provided by the Full profile
of DISelect. It is not available in the Basic profile. A DISelect Basic
processor encountering an AVT must raise a
deselect-compute-exception
exception.
AVTs provide additional flexibility in the specification of the values of attributes in the host language. An AVT is an XPath expression that is evaluated to yield the value for a host language attribute. AVTs are enclosed in curly braces {} (Unicode code points U+007B and U+007D, respectively) to distinguish them from literal values for attributes. The expressions used within an AVT can include any XPath expression supported by the DISelect Full processor. During processing, the value is computed and is used as the value of the attribute.
The examples in this section are informative. They have been chosen for clarity and simplicity. They are not intended to represent best practice. The companion primer [DI Primer] discusses a variety of ways to use DISelect under different circumstances.
This example illustrates the use of a variable within an attribute of the
host language. Two variables are defined in the example. Variable
isColor
is set by a call to the function dcn:cssmq-color.
This function returns a value of zero if the device does not support color.
The value of isColor
is used to control the value of variable
presClass
. The value of variable presClass
is used,
in an AVT, to specify the value of the class
attributes on
various elements in the host markup. The DISelect processor replaces the
expressions in each AVT with the appropriate value, and this is subsequently
used by the host language element. The different values of the
class
attribute select different CSS styles appropriate for
monochrome and color devices.
<sel:variable name="isColor" value="dcn:cssmq-color(0)"/> <sel:variable name="presClass" value="'colorDisplay'"/> <sel:if expr="$isColor = 0"> <sel:variable ref="presClass" value="'monochromeDisplay'"/> </sel:if> ... <h3 class="{$presClass}">Latest Cricket News</h3> <dl class="{$presClass}"> <dt>South Africa win latest one day international</dt> <dd>In a thrilling run chase, England yesterday just failed to overtake South Africa's mammoth score of 311.....</dd> <dt>Flintoff layoff will last four months</dt> <dd>Following recent surgery to correct a recurring injury problem, .......</dd> </dl>
In this example, the two different values of the class
attribute reference entries in the associated CSS style sheet that contain
definitions appropriate for use on devices with color and monochrome displays
respectively. The example is intended primarily to illustrate the syntax of
the use of AVTs and is not necessarily realistic. Note the quoting required
around the string literal values colorDisplay
and
monochromeDisplay
.
This section is normative.
DISelect uses XPath 1.0 [XPath 1.0] to express the calculations and conditions involved when determining whether or not a particular piece of content is to be included for processing. This specification defines two levels of support for XPath 1.0. One applies to the Basic Profile of DISelect and the other to the Full Profile.
Both DISelect Basic and DISelect Full processors must provide the XPath 1.0 subset defined in section 8.2 DISelect Basic XPath Support. In addition, DISelect Full processors must provide the XPath 1.0 support defined in section 8.3 DISelect Full XPath Support.
A DISelect Basic processor encountering features belonging solely in the DISelect Full profile must raise an diselect-compute-exception exception.
The two functions described in this section are useful for a content
author to determine which profile and which version of DISelect are
supported. Both functions must be supported by DISelect processors.
Both are defined in the DISelect namespace, bound to the prefix
"sel
" in the prototypes below.
getProfileName
functionstring sel:getProfileName()
This function returns a string which contains the name of the DISelect
profile that the processor supports. Upon evaluating this function, a
DISelect Basic processor must return the string
"Basic
", while a DISelect Full processor must return
the string "Full
".
sel:getVersion
functionstring sel:getVersion()
This function returns a string which contains the name of the DISelect profile that the processor supports. Upon evaluating this function, a DISelect 1.0 processor must return the string "1.0". Future versions of this specifications may define other possible values.
The subset of XPath 1.0 defined in this section must be supported by all DISelect processors. The subset is sufficient to construct conditional expressions and expressions that return values. It also includes the ability to invoke XPath functions. It specifically omits the ability to construct expressions that contain paths.
DISelect makes use of XPath functions for access to the delivery context. These functions provide a means of abstraction that hides the specific details of the representations used in the delivery context from the markup that references it.
There is a specific set of XPath functions, which must be supported by DISelect processors. This set of functions is described in the companion specification Delivery Context: XPath Access Functions 1.0 [DCN XAF], in the section describing the convenience functions. In addition to this set, DISelect processors mayoptionally support otherextension functions. Such extension functions are described in 8.4 Extension Functions.
Note:
It is anticipated that, in future, additional sets of XPath functions will be defined that will allow alternative ways of accessing the delivery context.It is anticipated that, in future, additional sets of functions will be defined for more comprehensive access to the delivery context. The delivery context is essentially a set of metadata, and some representations of it, such as CC/PP [CC/PP], use technologies such as RDF [RDF Primer] to provide semantically rich definitions. It is expected that additional sets of functions will be developed in future specifications to provide access to the delivery context in ways that reflect its role as metadata.
The formal grammar for the XPath subset used in DISelect Basic expressions is defined using the same, simple Extended Backus-Naur Form (EBNF) notation, as is used in [XPath 1.0].
[1] | DISelectExpr |
::= | OrExpr |
[2] | OrExpr |
::= | AndExpr |
| OrExpr 'or' AndExpr |
|||
[3] | AndExpr |
::= | EqualityExpr |
| AndExpr 'and' EqualityExpr |
|||
[4] | EqualityExpr |
::= | RelationalExpr |
| EqualityExpr '=' RelationalExpr |
|||
| EqualityExpr '!=' RelationalExpr |
|||
[5] | RelationalExpr |
::= | AdditiveExpr |
| RelationalExpr '<' AdditiveExpr |
|||
| RelationalExpr '>' AdditiveExpr |
|||
| RelationalExpr '<=' AdditiveExpr |
|||
| RelationalExpr '>=' AdditiveExpr |
|||
[6] | AdditiveExpr |
::= | MultiplicativeExpr |
| AdditiveExpr '+' MultiplicativeExpr |
|||
| AdditiveExpr '-' MultiplicativeExpr |
|||
[7] | MultiplicativeExpr |
::= | UnaryExpr |
| MultiplicativeExprMultiplyOperatorUnaryExpr |
|||
| MultiplicativeExpr
'div' UnaryExpr |
|||
| MultiplicativeExpr
'mod' UnaryExpr |
|||
[8] | MultiplyOperator |
::= | '*' |
[9] | UnaryExpr |
::= | UnionExpr |
| '-' UnaryExpr |
|||
[10] | UnionExpr |
::= | DISelectBasicPathExpr |
| UnionExpr '|' DISelectBasicPathExpr |
|||
[11] | DISelectBasicPathExpr |
::= | FilterExpr |
[12] | FilterExpr |
::= | PrimaryExpr |
| FilterExprPredicate |
|||
[13] | PrimaryExpr |
::= | VariableReference |
| '(' DISelectBasicExpr ')' |
|||
| Literal |
|||
| Number |
|||
| FunctionCall |
|||
[14] | VariableReference |
::= | '$' QName |
[15] | Literal |
::= | '"' [^"]* '"' |
| "'" [^']* "'" |
|||
[16] | Number |
::= | Digits ('.' Digits ?)? |
| '.' Digits |
|||
[17] | Digits |
::= | [0-9]+ |
[18] | FunctionCall |
::= | FunctionName '(' ( Argument ( ',' Argument )* )? ')' |
[19] | FunctionName |
::= | BaseFunctionName |
| ExtensionFunctionName |
|||
[20] | BaseFunctionName |
::= | ConvenienceFunctionName |
[21] | Argument |
::= | DISelectBasicExpr |
[22] | NodeType |
::= | 'comment' |
| 'text' |
|||
| 'processing-instruction' |
|||
| 'node' |
|||
[23] | Predicate |
::= | '[' PredicateExpr
']' |
[24] | PredicateExpr |
::= | DISelectBasicExpr |
These are the convenience functions that every DISelect processor must support. They are documented in the companion specification Delivery Context: XPath Access Functions 1.0 [DCN XAF], in the section describing the convenience functions.
Additional functions that are available to the DISelect processor
can be used within selection expressions. Such functions can be defined
to the processor using the functions
attribute (see 4.4 The functions
Attribute). Such definitions allow the processor to verify the
availability of the functions.
DISelect Full processors must provide support for full XPath 1.0 expressions. This support includes a complete implementation of XPath 1.0 [XPath 1.0] in addition to providing implementations of all of the XPath functions described the companion specification Delivery Context: XPath Access Functions 1.0 [DCN XAF]. In addition to the convenience functions, that specification defines additional functions that provide path-based access. These can be used with the delivery context and the host document.
In addition to access via the convenience functions, the Full Profile of DISelect provides direct access to the delivery context via path expressions. The dcn:delivery-context() function, defined in [DCN XAF], provides the means by which the root of the delivery context can be accessed. Paths within the delivery context are relative to this point. For example, the expression
dcn:delivery-context()/beverage/coffee[3]
returns the third coffee
node below the beverage
node which is itself below the root of the delivery context. Normal XPath 1.0
[XPath 1.0] rules apply to the way that the
resulting node is used. Naturally, to use the path-based access to delivery
context information, the author needs to be aware of the contents of the
delivery context, and the way in which it is structured. Suppose, for
example, that a particular implementation of delivery context includes an
element from a particular namespace that indicates location, and that one of
its child elements indicates the name of the city in which the device is
currently located.
<variable name="city" value="dcn:delivery-context()/geo:location/geo:city-name"/>
In this example, the markup sets the value of variable city
to the value of the geo:city-name
node beneath the
geo:location
node in the delivery context.
Note that to use path-based access to the delivery context, an author must be aware of the representation used by the particular DISelect processor.
In addition to providing access to the delivery context, the Full Profile of DISelect also provides access to the host document from within XPath expressions. Consequently, decisions about the inclusion of material can be based on the contents of the host document, the contents of the delivery context or a combination of the two.
Access to the host document is achieved by means of normal XPath 1.0 [XPath 1.0] facillities. If a DISelect processor provides this support, it must treat path expressions as applying to the source infoset by default. Path expressions that access the delivery context make use of XPath functions. This kind of access is described in section 8.3.1 Path-Based Access to the Delivery Context. Use of specific functions allows host document access to be distinguished from delivery context access.
<body> <p>Here is a paragraph.</p> <p id="important">Here is a paragraph which carries an id.</p> <p expr="//body/p[@id='important']">Here is a paragraph which is included if there is also a paragraph carrying an id value of important present within the body.</p> </body>
In this example, a host document contains three paragraphs. The third
paragraph contains an expr
attribute. The expression within this
attribute ensures that the third paragraph is only included in the result
infoset if there is also a paragraph which carries an id
attribute with the value important
.
In this example, an absolute path has been used. Relative paths may also be used to access the host document. In this case, the path is relative to the element that contains the expression making the reference.
Both DISelect Basic and DISelect Full processors mayoptionallysupport additional, implementation-specific, XPath functions. These functions might, for example, provide additional information from the delivery context. Such functions are known as extension functions.
Extension functions must not be placed in the DISelect namespace nor in the Delivery Context namespace. These namespaces are described in 2.1 The Namespaces. This is important because it is anticipated that additional sets of XPath functions will be defined in future versions of specifications related to DISelect. The DISelect and Delivery Context namespaces are reserved for such use.
The provision of the ability to provide extension functions recognizes that there is a need for capabilities beyond those described within this specification. The current diversity in representations of delivery context makes it difficult to define a standard yet comprehensive set of access functions. Instead, this specification defines a core set of such functions but allows for implementation-specific extensions. In future, it is anticipated that a wider range of types of access to the delivery context will become standardized.
Both DISelect Basic and DISelect Full processors may support additional functions over and above those defined in section 8.2 DISelect Basic XPath Support. These functions are known as extension functions.
Extension functions must notbe placed in the DISelect namespace nor in the Delivery Context namespace. These namespaces are described in section 2.1 The Namespaces. This is important because it is anticipated that, in future, additional sets of functions will be defined, in future versions of specifications related to DISelect, to provide more comprehensive access to the delivery context. These functions will be defined within the Delivery Context namespace
The delivery context is essentially a set of metadata. Some representations of delivery context, such as [CC/PP], use technologies such as RDF [RDF Primer] to provide semantically rich definitions. It is expected that additional sets of functions will be developed in future specifications to provide access to the delivery context in ways that reflect its role as metadata.
The schema for DISelect is available as a W3C XML Schema.
This section summarizes the changes made since the version of the document issued as a second last call.
Corrected the typographic error that suggested, erroneously, that this specification has a dependency on XHTML 2
Corrected the typographical errors that caused problems with white space
Corrected the typographical error that left discussion of default behaviour, when the expr attribute is omitted, in the document. This discussion is a matter for the host language, not for DISelect
Corrected the unnecessary use of escape characters within some of the XPath expressions used in the examples
Corrected the typographical error that resulted in two copies of one of the examples being present in the document
Corrected the typographical error that caused non-standard terminology to be used in references to the class attribute in host languages
Clarify the text that describes how DISelect elements and attributes do not appear in the result infoset to remove the ambiguity
Clarify the text that describes how the DISelect namespace can be used to remove the ambiguity and the unintended impression that host languages were prevented from subsuming DISelect
Clarified the conformance statements for the specification
This document was produced with the help of the Ubiquitous Web Application Group participants:
The editors would also like to recognize the contributions of the members of the former Device Independence Working Group: