Export (0) Print
Expand All

Specifying XPath Variables in XPath Queries

SQL Server 2000

The following examples show how XPath variables are passed in XPath queries. The XPath queries in these examples are specified against the mapping schema contained in SampleSchema1.xml. For information about this sample schema, see Sample XPath Queries.

A. Use the XPath variables

A sample template consists of two XPath queries. Each of the XPath queries takes one parameter. The template also specifies default values for these parameters. The default values are used if parameter values are not specified. Two parameters with default values are specified in <sql:header>.

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
     <sql:param name='CustomerID'>ALFKI</sql:param>
     <sql:param name='EmployeeID'>1</sql:param> 
  <sql:xpath-query mapping-schema="SampleSchema1.xml">
  </sql:xpath-query >
  <sql:xpath-query mapping-schema="SampleSchema1.xml">

This template is stored in a file (MyTemplate.xml) and executed using a URL:


In the URL, no parameters are passed. Therefore, the default parameter values are used.

In the following URL, the CustomerID parameter value is provided. Therefore, the default customer ID value ALFKI is ignored. Because no value is provided for the EmployeeID parameter, the default value is used.


In the following URL, both parameter values are passed (default values are ignored).


Note  The XPath query can be specified directly in the URL: http://IISServer/nwind/schema/SampleSchema1.xml/Customer[@CustomerID=$CustomerID]?CustomerID=ANATR&root=root.

The virtual name schema is of schema type. The schema file is stored in the directory associated with virtual name of schema type. The root parameter is used to specify a top-level element for the resulting XML document (root can be any value).

© 2015 Microsoft