The following example shows how to specify an axis in an XPath query. The XPath queries in these examples are specified on the mapping schema contained in SampleSchema1.xml. For information about this sample schema, see Sample XPath Query.
Example
A. Retrieve the child elements of the context node
This XPath queries all
/child::Employee
In this query, child is the axis and Customer is the node test (this test is TRUE if Customer is an
child is the default axis. Therefore, the query can be written as:
/Employee
Testing the XPath query on the mapping schema
Create the following template (MyTemplate.xml) and save it in the directory associated with the template virtual name .
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:xpath-query mapping-schema="SampleSchema2.xml"> /Employee </sql:xpath-query> </ROOT>
The following URL executes the template:
http://IISServer/VirtualRoot/template/MyTemplate.xml
XPath query can be specified directly in the URL:
http://IISServer/nwind/schema/SampleSchema1.xml/child::Customer?root=root
The virtual name schema is the schema type. Schema files are stored in the directory associated with the schema type virtual name. The root parameter specifies the top-level element for the resulting XML document (root can be any value).
The following is a partial result set of template execution:
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <Employee EmployeeID="1" LastName="Davolio" FirstName="Nancy" Title="Sales RePResentative" /> <Employee EmployeeID="2" LastName="Fuller" FirstName="Andrew" Title="Vice President, Sales" /> ... </ROOT>
B. Retrieve the grandchild nodes of the context node
This XPath queries all < of the
/child::Customer/child::Order
In this query, child is the axis, Customer and Order are node tests (if Customer and Order are
child is the default axis. Therefore, this query can be specified as:
/Customer/Order
Testing the XPath query on the mapping schema
Create the following template (MyTemplate.xml) and save it in the in the directory.
<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:xpath-query mapping-schema="SampleSchema1.xml"> /Customer/Order </sql:xpath-query> </ROOT>
The above is the content of specifying the axis in the XPath query (reprinted from the MSSQL manual). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!