XPath/CSS Equivalents

=CSS Equivalents= :disabled Equivalent represented

represents

represents

represents

represents

represents

Starts with Equivalent represents

Contains Equivalent represents

Ends with Equivalent represents

Like Equivalent represents

Negation Attribute Equivalent represents

ID Equivalent represents

represents

Class Equivalent represents

Descendant Equivalent represents

Child Equivalent represents

Adjacent Sibling Equivalent represents

General Sibling Equivalent represents

=CSS3 / jQuery Equivalents= :nth-last-child(n) query represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

represents

-moz-any/-webkit-any query represents

=DOM Equivalents= represents

represents

represents

represents

represents

represents

=Conditional Logic Equivalents= -A predicate is like a SQL where clause

-A pipe is like a SQL union clause

-An axis is like a SQL t1.col = t2.col

-Use a predicate with a boolean variable check as an if statement

-Use a pipe with a tagname search as a range checker

//h2 | //h3 | //h4

-Use a pipe with a negation predicate variable check as an else statement

//var[//var] | //var[not //var]

-Use a repeating axis to skip levels in the tree to retrieve nodes at every other branch

child::*/child::*

-Use variables to store individual checks within complex and/or conditional tests

-Use variables within loops to store iteration dependent variables and separate the logic from the output

-Use string-length to test the existence of functions

-Use separate tests like (a and c) or (b and c) instead of nested conditions like ((a or b) and c)

-Use string(.), local-name(.), string-length(concat(., '') ), number(.), and boolean(.)[boolean(.)] to test node values, names and existence

-Use //node[local-name(.) = $myvar] to test for the existence of form values

-Use //node[local-name(.) = $myvar][boolean(node)] to skip empty form values

-Always skip empty nodes when debugging

-Use local-name(.)[boolean(.)] to test for empty tags in the context node

-Use boolean(@*[not aa or not bb]) to filter known attributes

-Use {boolean((string$myvar))} to test interpolated variables

-Use boolean(following::*[1] or following::. or following::self::*) to test closing tag failures

-Use count(//*[1 | last = 1]) to count nodes with only one child

-Use (table1 | table2)[col=val]/* to do a join

-Use *[not(@*)] to return nodes that have no attributes

-Use number(.) - number(.) to suppress number values

-Use substring(., 0, string-length(.) ) to suppress string values

-Use substring('0', 1, not($myvar) ) to set an undefined variable to zero

-Use normalize-whitespace($myvar) to remove tab characters in lists

-Use translate($myvar, $ABCvar, $abcvar) with variables storing A-Z and a-z to ignore case for node queries

-Use string-length instead of contains when checking for list position to make logic data independent

-Use use-attribute-sets to share boilerplate arguments with multiple elements, such as table or list rows

-Use * or self::* whenever selecting to return a nodeset or single node

-Use string(.) to get a node from an XML file called with the document function

-Use different delimiters between each list item to make substring-before/after logic more readable

-Use string concatenation of node/class names with counter/node values to generate ID attributes

-Use a variable to store the previous index value with a comma to make substring-after work with recursion

-Use a predicate with the boolean value of the node as a guard operator

smyvar[$myvar]

-Use XSL nodes to store local values and test XML nodes in predicates with a pipe to emulate a default operator $dynamic[$var] | $default[not($var)]

-Use the child axis instead of slash for grouping child nodes

child::(boy | girl)

-Avoid (*) because it walks the tree before testing child nodes

-Use node instead of. when searching all elements using //

-Use a predicate check of the generate-id of the node itself and a node variable to do intersect and except set operations

-Use concat with a node and a dummy param to check for node existence

-Use string(number(.))=NaN to check existence of numeric node values

-Use not($a=$b) instead of $a !=$b when comparing variables that contain more than one node

-Use newlines after parentheses to avoid leaving one open ended

-Use predicates to check if form field names exist in the XML doc

-Use qname to get the namespace binding of a tag

-Use id to get generate-id values instead of variable interpolation