The set value element

Set value elements allow you to associate a set of database values with a give set name. For example here we associate a set of state names with the phrase "west coast":

    <column id="name" type="text" lex="name,names,named,called">
        <set_value lex="west coast">
            <element val="California"/>
            <element val="Oregon"/>
            <element val="Washington"/>
            ...
        </set_value>
    ...
    

Here we see the DTD definition for the set_value element:

    <!ELEMENT set_value (element*|#PCDATA)>
    <!ATTLIST set_value
              lex CDATA #REQUIRED
              description CDATA #IMPLIED>
    <!ATTLIST element
              val CDATA #REQUIRED>

    

lex is the comma separated phrases associated with the set value (e.g. "west coast").

The sub-element element gives a value within the set. It has the a single tag attribute val that gives the literal value.

In the case that PCDATA is supplied as sub-element, it gives SQL that defines the set value. Note that this is SQL that get plugged into a query and gets executed at query time. An example use of this follows over a SQLite database.

        <set_value lex="next weekend"><![CDATA[
            SELECT day FROM Date_DIMENSION
            WHERE day < DATE('now','weekday 1') AND
            weekday IN ('Saturday','Sunday')
            ORDER BY day DESC LIMIT 2
        ]]></set_value>
    

In this particular application, this lets users use expressions such as "next weekend" and C-Phrase dynamically, at query time, determines exactly which dates that constitutes.