Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>a) Can I automatically get a value of boolean true|false directly from the string 'true|false' ? </p> <p>b) Is there an (xpath?) construct to map the boolean true|false to '*', '' ?</p> </blockquote> <p><strong>This is actually an XPath question</strong>.</p> <p><strong>I. XPath 1.0</strong></p> <p>There are more than one XPath expressions the evaluation of which produces the wanted result:</p> <pre><code>substring('*', 2 -(@flag = 'true')) </code></pre> <p>This also answers b) -- notice that the <em>strings</em> <code>'true'</code> and <code>'false'</code> aren't boolean values! The only two boolean values are <code>true()</code> and <code>false()</code> and they are not strings.</p> <p>In the above expression we use the fact that in XPath 1.0 if a boolean is in a context where a number is needed, it is automatically converted to number. By definition:</p> <p><code>number(true())</code> is <code>1</code></p> <p>and</p> <p><code>number(false())</code> is <code>0</code></p> <p>Thus the second argument of the call to <code>substring()</code> above:</p> <pre><code>2 - (@flag = 'true') </code></pre> <p>is evaluated as <code>1</code> when <code>@flag = 'true'</code> and to <code>2</code> otherwise.</p> <p><strong>A more general XPath 1.0 expression that produces the string <code>$s1</code> if <code>$val</code> is <code>"x"</code> and produces the string <code>$s2</code> if <code>$val</code> is <code>"y"</code></strong> :</p> <pre><code>concat(substring($s1, 1 div ($val = "x")), substring($s2, 1 div ($val = "y")) ) </code></pre> <p>This produces the string <code>$s1</code> when <code>$val = "x"</code>, the string <code>$s2</code> when <code>$val = "y"</code>, and the empty string -- if none of these two conditions holds.</p> <p>The above XPath 1.0 expression can be generalized to produce N different string results <code>$s1</code>, <code>$2</code>, ..., <code>$sN</code> exactly when <code>$val</code> is one of the values <code>$v1</code>, <code>$v2</code>, ..., <code>$vN</code> because the function <code>concat()</code> can have any number of arguments.</p> <hr> <p><strong>II. XPath 2.0 (XSLT 2.0)</strong></p> <pre><code>'*'[current()/@flag = 'true'] </code></pre> <p>And more generally, given 2*N atomic values <code>$s1</code>, <code>$s2</code>, ... <code>$sN</code> and <code>$v1</code>, <code>$v2</code>, ..., <code>$vN</code>, such that all <code>$vi</code> values are different, the result of evaluating this XPath 2.0 expression:</p> <pre><code> ($s1, $s2, ..., $sN)[index-of(($v1, $v2, ..., $vN), $v)] </code></pre> <p>is <code>$sK</code> exactly when <code>$v eq $vK</code>.</p>
    singulars
    1. This table or related slice is empty.
    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