title: Trying to understand multiple predicates
body: <p>I came across <a href="http://xpather.com" rel="nofollow noreferrer">http://xpather.com</a>, which lets you write XPath expressions. It comes with a sample XML document which is similar to this one:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;app&gt;
     &lt;abstract&gt;a&lt;/abstract&gt;
     &lt;description&gt;
        &lt;subject&gt;s1&lt;/subject&gt;
        &lt;subject&gt;s2&lt;/subject&gt;
     &lt;/description&gt;
     &lt;extra-notes&gt;
        &lt;note&gt;n1&lt;/note&gt;
        &lt;note&gt;n2&lt;/note&gt;
        &lt;note&gt;n3&lt;/note&gt;
        &lt;note&gt;n4&lt;/note&gt;
     &lt;/extra-notes&gt;
  &lt;/app&gt;
  </code></pre>
  <p>and has a sample XPath expression: <code>.//*[self::abstract or self::subject or self::note][position() &lt;= 2]</code></p>
  <p>The result sequence is</p>
  <pre class="lang-xml prettyprint-override"><code>   &lt;abstract&gt;a&lt;/abstract&gt;
     &lt;subject&gt;s1&lt;/subject&gt;
     &lt;subject&gt;s2&lt;/subject&gt;
     &lt;note&gt;n1&lt;/note&gt;
     &lt;note&gt;n2&lt;/note&gt;
  </code></pre>
  <p>Now I am trying to understand why the result is like this: The first predicate selects all abstract, subject and note elements and the second predicate limits this to <code>position() &lt;= 2</code>. My intuitive expectation would be that the XPath expression only selects two nodes (abstract and subject1), but it actually selects the first two elements from each of the selected nodes. What is exactly going on?</p>
  <p>Just for testing: here is my simple stylesheet:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;xsl:stylesheet version=&quot;2.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
    &lt;xsl:output indent=&quot;yes&quot;/&gt;
    &lt;xsl:template match=&quot;/&quot;&gt;
      &lt;e&gt;
        &lt;xsl:copy-of select=&quot;.//*[self::abstract or self::subject or self::note][position() &amp;lt;= 2]&quot;/&gt;
      &lt;/e&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>