About the XPath Processor

The XML editor in Stylus Studio supports both the W3C XPath 1.0 Recommendation and the W3C XPath 2.0 Working Draft of November 2003. By default, Stylus Studio uses its XPath 1.0 processing engine. You can select the XPath 2.0 processing engine by clicking the v.2 icon ( )in the XML editor tool bar.

As an overview of the XPath processor, this section provides the following information:

For additional information about XPath see http://www.w3.org/TR/xpath and http://www.w3.org/TR/xpath20 .

Where You Can Specify Queries

When you use Stylus Studio, you specify queries as values of match and select attributes in stylesheets. In this way, you use queries to select the nodes you want to transform and query.

You can also specify a query at the top of an XML document window. In the Query Output window, Stylus Studio displays the result of the query.

About XPath

XPath is a notation for retrieving information from a document. The information could be a set of nodes or derived values.

XPath allows you to identify parts of an XML document. In addition, a subset of XPath allows you to test whether or not a node matches a particular pattern. XPath provides Boolean logic, filters, indexing into collections of nodes, and more.

XPath is declarative rather than procedural. You use a pattern modeled on directory notation to describe the types of nodes to look for. For example, book/author means find all author elements that are contained in book elements.

XPath provides a common syntax for features shared by Extensible Stylesheet Language Transformations (XSLT) and XQuery. XSLT is a language for transforming XML documents into XML, HTML, or text. XQuery builds on XPath and is a language for extracting information from XML documents.

The basic syntax for XPath mimics the Uniform Resource Identifier (URI) directory navigation syntax. However, the syntax does not specify navigation through a physical file structure. The navigation is through elements in the XML tree.

Benefits of XPath

XPath is designed for XML documents. It provides a single syntax that you can use for queries, addressing, and patterns. XPath is concise, simple, and powerful. XPath has many benefits, as follows:

  • Queries are compact.
  • Queries are easy to type and read.
  • Syntax is simple for the simple and common cases.
  • Query strings are easily embedded in programs, scripts, and XML or HTML attributes.
  • Queries are easily parsed.
  • You can specify any path that can occur in an XML document and any set of conditions for the nodes in the path.
  • You can uniquely identify any node in an XML document.
  • Queries return any number of results, including zero.
  • Query conditions can be evaluated at any level of a document and are not expected to navigate from the top node of a document.
  • Queries do not return repeated nodes.
  • For programmers, queries are declarative, not procedural. They say what should be found, not how it should be found. This is important because a query optimizer must be free to use indexes or other structures to find results efficiently.
  • XPath is designed to be used in many contexts. It is applicable to providing links to nodes, for searching repositories, and for many other applications.

When you define a query, keep in mind that XML data can be represented as a tree. A tree is a hierarchical representation of XML data. The root node is the top of the tree. Each element, attribute, text string, comment, and processing instruction corresponds to one node in the tree. A tree also shows the relationships among the nodes. For more information on tree structure, see Tree Representation of a Sample XML Document.

Internationalization

Queries can contain non-Latin characters.

Restrictions on Queries

XPath is a language for selecting existing XML data; it does not perform manipulation (like sorting) or construction of different XML structures. To perform such operations, you need to use the language that is hosting XPath, XSLT or XQuery, for example.

You cannot query non-XML data. If you query a document that does not contain XML-formatted data, Stylus Studio displays an error message that informs you that the queried text is not XML.

 
Free Stylus Studio XML Training: