Download presentation
Presentation is loading. Please wait.
Published byJeffery Arron Parsons Modified over 9 years ago
1
XPath Eugenia Fernandez IUPUI
2
XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing information found in the document node tree used to navigate to and address components of an XML document
3
Dealing with Abstraction All input and output documents in XSLT are manipulated in an abstract fashion The input XML document is transformed into an abstract source node tree The XSLT processor performs all operations on the source node tree, not the original document A new output node tree is created as the result of the transformation XPath is used to navigate the source node tree
4
An XML Tree Jake 23000 XML Document Document root ID 123Jake23000 Tree Structure
5
Types of Nodes 1. Root every XML document has a single root node, the only node without a parent, corresponds to the document, above the XML root element 2. Element 3. Attribute not children of their defining elements located along separate attribute axis IMPLIED attributes are not defined in the tree if attribute has a default value in the DTD it appears in the node tree
6
Type of Nodes 4. Text any sequence of consecutive characters, including whitespace 5. Namespace attached to all elements describes the namespace definitions 6. Processing instruction but not the declaration 7. Comment
7
Node Properties Each node has four properties value of the node name of the node parent node set of child nodes
8
Location Paths An XPath expression for locating nodes in an XML document absolute location paths defines location relative to root node begins with / (/ specifies the root) relative location paths defines location relative to current node does not begin with / current node changes at every step can specify axis (direction) to move in
9
Building Location Paths Made up of location steps relative path product/price absolute path/catalog/product/price Location steps evaluated left to right
10
Location Steps Each location step made up of three parts axis::node-test [predicate] axis – indicates the direction from current node, e.g. child axis selects child elements, the attribute axis selects attributes node-test specifies nodes by their type or their name returns a set of nodes or a node-set predicate Boolean expression that filters the node-set obtained by node-test enclosed in []
11
Node Tests by type along any axis processing-instruction() comment() text() node() by name the character * all elements
12
Location Step Example child::product[price>35][3] this is a relative path searches from current node through the child axis finds all child product elements the 1 st predicate filters the product elements to those who have a price element > 35 the 2 nd predicate keeps the third one only
13
XPath Axes self child parent attribute descendant descendant-or-self ancestor ancestor-or-self following following-sibling preceding preceding-sibling namespace For more information visit http://www.brics.dk/~amoeller/XML/linking-4.2.1.html
14
XPath Axes self 1 3 11 16 6578 24 1091213 17181514 parent ancestor child descendent preceding-sibling following-sibling following preceding
15
Axes Examples select=“child::partNbr” child elements from the current node with the name partNbr select=“preceding::partNbr” all partNbr nodes that appear before the current node not including ancestors & attributes select=“../partNbr” sibling & self nodes with the name partNbr by first going to the parent (with..) and then to the parent’s children (with /)
16
Shortcuts No axis implies the child:: axis the @ character = the attribute axis, i.e., attribute::. = self::node() or the current node.. = parent::node() the parent node // = /descendant-or-self::node()/ i.e., all descendents
17
Using Predicates By position [3] or [last()] numbered in proximity order to current node along the axis reverse axis ancestor, ancestor-or-self, preceding, preceding-sibling, numbered in reverse document order, or in reverse direction from current node forward axis all other axes, numbered in document order or forward from current node
18
Using Predicates By Presence product[@code] child product element which has a code attribute By Value product[@code=“123”] child product element with code attribute with value of “123”
19
Sources “Practical Transformation using XSLT and Xpath”, G. Ken Holman, presentation at XML One Conference, Chicago, IL, May, 2001. “Exchanging and Transforming Data Using XML and XSLT”, a Microsoft Certified Course.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.