Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Depending on your exact situation, there are different XPath expressions that will select the node</strong>, whose value contains some whitespace.</p> <p>First, let us recall that any one of these characters is "whitespace":</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong><code>&amp;#x09;</code></strong> -- the Tab</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong><code>&amp;#xA;</code></strong> -- newline</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong><code>&amp;#xD;</code></strong> -- carriage return</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong><code>' '</code></strong> or <strong><code>&amp;#x20;</code></strong> -- the space</p> <p>If you know the exact value of the node, say it is "<code>Hello World</code>" with a space, then a most direct XPath expression:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><code>/top/aChild[. = 'Hello World']</code></strong></p> <p>will select this node.</p> <p><em>The difficulties with specifying a value that contains whitespace, however, come from the fact that we see all whitespace characters just as ... well, whitespace</em> and don't know if a it is a group of spaces or a single tab.</p> <p><strong>In <a href="http://www.w3.org/TR/xpath20/" rel="noreferrer">XPath 2.0</a> one may use <a href="http://www.w3.org/TR/xpath-functions/#regex-syntax" rel="noreferrer">regular expressions</a> and they provide a simple and convenient solution</strong>. Thus we can use an XPath 2.0 expression as the one below:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong><code>/*/aChild[matches(., "Hello\sWorld")]</code></strong></p> <p>to select any child of the top node, whose value is the string "Hello" followed by whitespace followed by the string "World". <strong>Note</strong> the use of the <a href="http://www.w3.org/TR/xpath-functions/#func-matches" rel="noreferrer"><strong><code>matches()</code></strong></a> function and of the "<strong><code>\s</code></strong>" pattern that matches whitespace.</p> <p><strong>In <a href="http://www.w3.org/TR/xpath" rel="noreferrer">XPath 1.0</a></strong> a convenient test if a given string contains any whitespace characters is:</p> <p><strong><code>not(string-length(.)= stringlength(translate(., ' &amp;#9;&amp;#xA;&amp;#xD;','')))</code></strong></p> <p>Here we use the <a href="http://www.w3.org/TR/xpath#function-translate" rel="noreferrer"><strong><code>translate()</code></strong></a> function to eliminate any of the four whitespace characters, and compare the length of the resulting string to that of the original string.</p> <p>So, if in a text editor a node's value is displayed as </p> <p>"Hello&nbsp;&nbsp;&nbsp;&nbsp;World", </p> <p>we can safely select this node with the XPath expression:</p> <p><strong><code>/*/aChild[translate(., ' &amp;#9;&amp;#xA;&amp;#xD;','') = 'HelloWorld']</code></strong></p> <p>In many cases we can also use the XPath function <a href="http://www.w3.org/TR/xpath#function-normalize-space" rel="noreferrer"><strong><code>normalize-space()</code></strong></a>, which from its string argument produces another string in which the groups of leading and trailing whitespace is cut, and every whitespace within the string is replaced by a single space.</p> <p>In the above case, we will simply use the following XPath expression:</p> <p><strong><code>/*/aChild[normalize-space() = 'Hello World']</code></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload