XML Tutorial/XPath/context

Материал из Web эксперт
Перейти к: навигация, поиск

Understanding Context

   <source lang="xml">

In XPath, the context indicates the location of the node where a processor is currently situated. That node is called the context node. The context also includes a context position and a context size. Consider the following XML document, book.xml: <Book>

   <Chapter number="1">This is the first chapter</Chapter>
   <Chapter number="2">This is the second chapter</Chapter>
   <Chapter number="3">This is the third chapter</Chapter>
   <Chapter number="4">This is the fourth chapter</Chapter>
   <Chapter number="5">This is the fifth chapter</Chapter>

</Book> Suppose the context node is the node that represents the Chapter element node for the second chapter. We can use the position() and last() functions to show the position of the context node and the context size.</source>