Using Annotated XSD Schemas for Creating XML Views tutorial
Filtering Values by Using sql:limit-field and sql:limit-value

## Preliminaries

Rows returned from a database query can be limited on the basis of some limiting value. The sql:limit-field is used to identify the database column that contains limiting values and sql:limit-value annotations is used to specify a specific limiting value to be used to filter the data returned. The sql:limit-value annotation is optional. If sql:limit-value is not specified, a NULL value is assumed.

## Example.

This is the mapping schema in which the 'product_Chai' schema attribute maps to the 'ProductID' column in the 'Demo.demo.Products' relation. The values that are returned for this attribute are limited to only 'ProductName' having the 'Chai' value by specifying the sql:limit-field and sql:limit-value annotations. Similarly, the 'product_Chang' schema attribute returns only the 'ProductID' limited to 'ProductName' having the 'Chang' value.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
    <xsd:annotation>
      <xsd:appinfo>
        <sql:relationship name="CategoryProduct"
              parent="Demo.demo.Categories"
              parent-key="CategoryID"
              child="Demo.demo.Products"
              child-key="CategoryID" />
      </xsd:appinfo>
    </xsd:annotation>

      <xsd:element name="category" sql:relation="Demo.demo.Categories" type="CategoryType" />
       <xsd:complexType name="CategoryType" >
         <xsd:sequence>
            <xsd:element name="product_Chai"
                           type="xsd:string"
                         sql:relation="Demo.demo.Products"
                         sql:field="ProductID"
                         sql:limit-field="ProductName"
                         sql:limit-value="Chai"
                         sql:relationship="CategoryProduct" >
            </xsd:element>
            <xsd:element name="product_Chang"
                           type="xsd:string"
                         sql:relation="Demo.demo.Products"
                         sql:field="ProductID"
                         sql:limit-field="ProductName"
                         sql:limit-value="Chang"
                         sql:relationship="CategoryProduct" >
            </xsd:element>
         </xsd:sequence>
            <xsd:attribute name="CategoryID"  type="xsd:integer" />
            <xsd:attribute name="description"  sql:field="Description"  type="xsd:string" />
        </xsd:complexType>

    </xsd:schema>

Let the schema is written to the file 'Cat_Product.xsd', then after loading this file by `xml_load_mapping_schema_decl` function, the first example will produce a result for the XPath query:

    XPATH [__view 'Cat_Product'] /*[@CategoryID=1]

the second example will produce a result for the XQuery query:

    select xquery_eval('<doc>{for $r in xmlview("Cat_Product")/*[@CategoryID=1] return $r}</doc>', xtree_doc('<q/>'))