<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
</catalog>
/catalog
/catalog/cd
/catalog/cd/price
/catalog/cd[price>10.80]
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
</catalog>
/catalog/cd/price
//cd
/catalog/cd/*
/catalog/*/price
/*/*/price
//*
/catalog/cd[1]
/catalog/cd[last()]
/catalog/cd[price]
/catalog/cd[price = 10.90]
/catalog/cd[price = 10.90]/price
/catalog/cd/title | /catalog/cd/artist
//title | //artist
//title | //artist | //price
/catalog/cd/title | //artist
//@country
//cd[@country]
//cd[@*]
//cd[@country = 'UK']
/step/step/...
step/step/...
axisname::nodetest[predicate]
child::price[price=9.90]
| AxisName | Description |
|---|---|
| ancestor | Contains all ancestors of the current node
This axis will always include the root node unless the current node is the root node. |
| ancestor-or-self | Contains the current node plus all it's ancestors |
| attribute | Contains all attributes of the current node |
| child | contains all children of the current node |
| descendant | contains all descendants of the current node
This axis never contains attribute or namespace nodes |
| descendant-or-self | Constains the current node plus al it's descendants |
| following | Contains everything in the document after the
closing tag of the current node |
| following-sibling | Contains all siblings after the current node.
If the current node is an attribute node or namespace node this axis will be empty |
| namespace | Contains all namespace nodes of the current node |
| parent | Contains the prent of the current node |
| preceding | Contains everything in the document that is before
the starting tag of the current node |
| preceding-sibling | Contains all siblings before the current node
If the current node is an attribute node or namespace node this axis will be empty |
| self | Contains the current node |
| Example | Result |
|---|---|
| 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 |
| attribe::src | Select 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 element 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 chidren 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 docuemnt root |
| Example | Result |
|---|---|
| child::price[price=9.90] | Selects all prices elements that are children of
the current node with a price element = 9.90 |
| child::cd[position()=1 | Selects the first cd child of the current node |
| child::cd[position()=last] | Selects the last cd child of the current node |
| child::cd[position()=last()-1 | Selets the last but one cd child of the current node |
| child::cd[position()<6] | Selects the first 5 cd children of the current node |
| /descendant:;cd[position()-7] | Selects the 7th cd element in the document |
| child::cd[attribute::type="classic"] | Selects all cd children of the current node having a
type attribute with the value of "classic" |
| Abbr | Meaning | Example |
|---|---|---|
| name | child:: | cd is short for child::cd |
| @ | attribute:: | cd[@type="classic"] is short for
child::cd[attribute::type="classic"] |
| . | self::node() | .//cd is short for
self::node()/descendant-orself::node()/child::cd |
| .. | parent::node() | ..//is short for
parent::node()/child::cd |
| // | /descendant-or-self::node()/ | //cd is short for
/descendant-or-self::node()/child::cd |
| Example | Result |
|---|---|
| cd | Selects all the cd elements that are children of the current node |
| * | Selects all child elements of the current node |
| text() | Selects all text node children of the current node |
| @src | Selects the src attribute of the current node |
| @* | Selects all attributes of the current node |
| cd[1] | Selects the first cd child of the current node |
| cd[last()] | Select the last cd child of the current node |
| */cd | Selects all cd grandchildren of the current node |
| /book/chaper[3]/para[1] | Selects the first para of the third chapter of the book |
| //cd | Selects all the cd descendants of the document root, and thus
selects all cd elements in the same document as the current node |
| . | Selects the current node |
| .//cd | Selects the cd element descendants of the current node |
| .. | Selects the parent of the current node |
| ../@src | Selects the src attribute of the parent of the current node |
| cd[@type="classic"] | Selects all cd children of the current node that have
a type attribute with the value "classic" |
| cd[@type="classic"][5] | Selects the 5th cd child of the current node that has
a type attribute with the value "classic" |
| cd[5][@type="classic"] | Selects the 5th cd child of the current node if that child
has a type attribute with the value "classic" |
| cd[@type and @country] | Selects all teh cd children of the current node that
have both a type attribute and a country attribute |
| Operator | Description | Example | Result |
|---|---|---|---|
| + | Addition | 6 + 4 | 10 |
| - | Subtraction | 6 - 4 | 2 |
| * | Multiplication | 6 * 4 | 24 |
| div | Division | 8 div 4 | 2 |
| mod | Modulus | 5 mod 2 | 1 |
| Operator | Description | Example | Result |
|---|---|---|---|
| = | Equal | price=9.90 | true if price = 9.90 |
| != | Not equal | price!=9.90 | false |
| Operator | Description | Example | Result |
|---|---|---|---|
| < | Less Than | price<9.90 | false if price is 9.90 |
| <= | Less Than or Equal to | price<=9.90 | true |
| > | Greater Than | price>9.90 | false |
| >= | Greater Than or Equal To | price>=9.90 | True |
| Operator | Description | Example | Result |
|---|---|---|---|
| or | or | price=9.90 or price=9.70 | true if price = 9.90 |
| and | and | price<=9.90 and price=9.70 | false |
| Name | Description | Syntax & Example |
|---|---|---|
| count() | Returns the number of nodes in a node-set | number=count(node-set) |
| id() | Selects elements by their Id | node-set=id(value) |
| last() | Returns the position number of the last node
in the processed node list |
number=last() |
| local-name() | Returns the local part of a node.
A node usually consists of a prefix, a colon, followed by the local name |
string=local-name(node) |
| name() | Returns the name of a node | string=name(node) |
| namespace-uri() | Returns the namespace URI of a node | uri=namespace-uri(node) |
| position() | Returns the position in the node list of
the current node |
number=position() |
| Name | Description | Syntax & Example |
|---|---|---|
| concat() | Returns the concatenation of all it's arguements | string-contcat(value1,value2,...) |
| contains() | Returns true if the second string is contained
within the first |
bool=contains(string,substring) |
| naormalize-space() | Removes leading/trailing spaces | string=normalize-space(string) |
| starts-with() | Returns true if the first string
starts with the second |
bool=starts-with(string,substr) |
| string() | Converts the value to a string | string(value) |
| string-length() | Returns the length | number=string-length(string) |
| substring() | Returns a part of the string | string=substring(string,start,length) |
| substring-after() | Returns everyting after the substring | string=substing-after(string,substr) |
| substring-before | Returns everything before the substring | string=substring-before(string,substr) |
| translate() | Performs a char by char replacement
like a replace |
string=translate(string,substring1,substring2 |
| Name | Description | Syntax & Example |
|---|---|---|
| ceiling() | Returns the smallest integer
that is not less than the number argument |
number=ceiling(number) |
| floor() | REturns the largest integer that is not
greater than the number argument |
number=floor(number) |
| number() | Converts a value to a number | number=number(value) |
| round() | integer=round(number) | |
| sum() | number=sum(nodeset) |
| Name | Description | Syntax & Example |
|---|---|---|
| boolean() | Converts to a boolean | bool=boolean(value) |
| false() | Returns false | |
| lang() | Returns true if the language argument
matches the language of the sl:lang element |
bool=lang(language) |
| not() | Returns true if the conditions is false | bool=not(condition) |
| true() | Returns true |
xmlobject.selectNodes(XPath expression)
xmlDoc.selectNodes("/catalog/cd")
xmlDoc.selectNodes("/catalog/cd[0]")
xmlDoc.selectNodes("/catalog/cd/price")
xmlDoc.selectNodes("/catalog/cd/price/text()")
xmlDoc.selectNodes("/catalog/cd[price>10.00]")
|
|
|