Download presentation
Presentation is loading. Please wait.
Published byNeil Edwards Modified over 9 years ago
1
The learning site: http://www.w3schools.com/xpath /xpath_syntax.asp http://nwalsh.com/docs/tutorials/ xsl/xsl/slides.html
3
Empire Burlesque Bob Dylan USA Columbia 10.90 1985.
4
Empire Burlesque Bob Dylan USA Columbia 10.90 1985.
5
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> My CD Collection Title Artist
6
What is XPath? 1. XPath is a syntax for defining parts of an XML document 2. XPath uses paths to define XML elements 3. XPath defines a library of standard functions 4. XPath is a major element in XSLT 5. XPath is not written in XML 6.XPath is a W3C Standard
7
XPath Example Empire Burlesque Bob Dylan 10.90 Hide your heart Bonnie Tyler 9.90 Greatest Hits Dolly Parton 9.90
8
Location steps an axis (specifies the tree relationship between the nodes selected by the location step and the current node) a node test (specifies the node type and expanded-name of the nodes selected by the location step) zero or more predicates (use expressions to further refine the set of nodes selected by the location step)
9
Axes
10
ancestor Ancestors of the current node ancestor-or-self - Ancestors, including the current node attribute - Attributes of the current node (abbreviated "@") child - Children of the current node (the default axis) descendant - Descendants of the current node descendant-or-self - Descendants, including the current node (abbreviated "//") following / following-sibling - Elements which occur after the current node, in document order preceding / preceding-sibling - Elements which occur before the current node, in document order (returned in reverse-document order) namespace - The namespace nodes of the current node parent - The parent of the current node (abbreviated "..") self - The current node (abbreviated ".")
11
child::cd -Selects all cd elements that are children of the current node (if the current node has no cd children, it will select an empty node-set) attribute::src - Selects the src attribute of the current node (if the current node has no src attribute, it will select an empty node-set) child::* - Selects all child elements of the current node attribute::* - Selects all attributes of the current node child::text() - Selects the text node children of the current node child::node() - Selects all the children of the current node descendant::cd - Selects all the cd element descendants of the current node ancestor::cd - Selects all cd ancestors of the current node ancestor-or-self::cd - Selects all cd ancestors of the current node and, if the current node is a cd element, the current node as well. child::*/child::price - Selects all price grandchildren of the current node / - Selects the document root
12
name - Matches element nodes * - Matches any element node namespace:name - Matches element nodes in the specified namespace namespace:* - Matches any element node in the specified namespace comment() - Matches comment nodes text() - Matches text nodes processing-instruction() - Matches processing instructions processing-instruction('target ’ ) - Matches processing instructions with the specified target node() - Matches any node Node Tests
13
Predicates nodetest[1] - Matches the first node nodetest[position()=last()] - Matches the last node nodetest[position() mod 2 = 0] - Matches even nodes element[@id='foo'] - Matches the element(s) with id attributes whos value is "foo" element[not(@id)] - Matches elements that don't have an id attribute author[firstname="Norman"] - Match elements that have children with the content "Norman". author[normalize-space(firstname)="Norman"] - Match "Norman" without regard to leading and trailing space. Predicate expressions can be more-or-less arbitrarily complex.
14
. - self @ - attribute ( cd[@type="classic"] is short for child::cd[attribute::type="classic"]).. - parent (../cd is short for parent::node()/child::cd) // - //cd is short for descendant-or- self::node()/child::cd
15
/catalog /catalog/cd /catalog/cd/price /catalog/cd[price>10.80] XPath Example(cont)
16
/catalog/cd/price /- represents an absolute path to an element // - all elements in the document that fulfill the criteria will be selected //cd /catalog/cd/* /catalog/*/price /*/*/price //* /catalog/cd[1] /catalog/cd[last()] /catalog/cd[price] /catalog/cd[price=10.90]
17
/catalog/cd[price=10.90]/price /catalog/cd/title | /catalog/cd/artist //@country //cd[@country] //cd[@*] //cd[@country='UK'] XPath Example(cont)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.