| Previous | Next
XPointers in LinksObviously, what an XPointer points to depends on to which document it's applied. This document is specified by the URL to which the XPointer is attached. For example, if you wanted a URL that pointed to the first http://www.cafeconleche.org/people.xml#xpointer(//name[position( )=1]) If the XPointer uses any characters that are not allowed in URIs--for instance, the less than sign In HTML, the URLs used in <a href = "http://www.cafeconleche.org/people.xml#xpointer(//name[1])"> The name of a person </a> If a browser followed this link, it would likely load the entire document at http://www.cafeconleche.org/people.xml and then scroll the window to the beginning of the first Since XPath can only locate nodes in a well-formed XML document, XPointers can only point into XML documents. You can't use them to link into nonwell-formed HTML, plain-text files, or other non-XML documents. However, linking from HTML documents is perfectly fine, as is printing XPointers in tutorials, painting them on the sides of buildings, or communicating them by any means by which text can be communicated. XPointers are more frequently used in XLinks. For example, this simple link points to the first <In_the_beginning xlink:type="simple" xlink:href="ot.xml#xpointer(/testament/tutorialcoll/tutorial[position( )=1])"> Genesis </In_the_beginning> In extended links, an XPointer can help identify both the starting and ending resources of an arc. For example, this extended XLink establishes an arc between the last <Bible xlink:type="extended" xmlns:xlink="http://www.w3.org/1999/xlink"> <testament xlink:type="locator" xlink:label="ot" xlink:href="ot.xml#xpointer(//v[position()=last( )])"/> <testament xlink:type="locator" xlink:label="nt" xlink:href="nt.xml#xpointer(//v[position( )=1])" /> <next xlink:from="ot" xlink:to="nt"/> <previous xlink:from="nt" xlink:to="ot"/> </Bible> Links can even be purely internal; that is, they can link from one place in the document to another place in the same document. The <slide xmlns:xlink="http://www.w3.org/1999/xlink"> <point>Acme Wonder Goo is a delicious dessert topping!</point> <point>Acme Wonder Goo is a powerful floor cleaner!</point> <point>It's two products in one!</point> <first xlink:type="simple" xlink:href="#xpointer(//slide[position( )=1])"> Start </first> <last xlink:type="simple" xlink:href="#xpointer(//slide[position()=last( )]))"> End </last> </slide> When the XPath expressions used in an XPointer are themselves relative, the context node is the root node of the entity that contains the XPointer. |