Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

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.

Examples
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:header>
     <sql:param name='CustomerID'>ALFKI</sql:param>
     <sql:param name='EmployeeID'>1</sql:param> 
  </sql:header>
  <sql:xpath-query mapping-schema="SampleSchema1.xml">
    Customer[@CustomerID=$CustomerID] 
  </sql:xpath-query >
  <sql:xpath-query mapping-schema="SampleSchema1.xml">
   Employee[@EmployeeID=$EmployeeID] 
  </sql:xpath-query>
</ROOT>

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

http://IISServer/VirtualRoot/template/MyTemplate.xml

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.

http://IISServer/VirtualRoot/template/MyTemplate.xml?CustomerID=BERGS

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

http://IISServer/VirtualRoot/template/MyTemplate.xml?CustomerID=BERGS&EmployeeID=2

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).

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.