title: XSLT check if a particular element is preceeded by a text node (why this does not work)
body: <p>I do not understand why checking whether an element (p in my case) is preceeded by a text node, using the following expression:</p>
  
  <p><code>preceding-sibling::node()[1][self::text()]</code></p>
  
  <p>does not work properly. Here is an example to illustrate:</p>
  
  <p><strong>Input</strong>:</p>
  
  <pre><code>&lt;div&gt; 
     simply a text node
     &lt;element /&gt;
     &lt;p/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>XSLT</strong>:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt;
  
     &lt;xsl:template match="@* | node()"&gt;
        &lt;xsl:copy&gt;
           &lt;xsl:apply-templates select="@* | node()"/&gt;
        &lt;/xsl:copy&gt;
     &lt;/xsl:template&gt;
  
     &lt;xsl:template match="p"&gt;
    &lt;xsl:if test="preceding-sibling::node()[1][self::text()]"&gt;
       &lt;br /&gt;
    &lt;/xsl:if&gt;
    &lt;xsl:copy&gt;
       &lt;xsl:apply-templates select="@*|node()" /&gt;
    &lt;/xsl:copy&gt;
     &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I was expecting that the <code>&lt;br /&gt;</code> does not get inserted because the node immediately preceeding <code>&lt;p /&gt;</code> is an element, not a text node. However the output is:</p>
  
  <pre><code>&lt;div&gt; 
     simply a text node
     &lt;element/&gt;
     &lt;br/&gt;
     &lt;p/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The same as if I would not have the <code>&lt;element/&gt;</code> node. Could someone please point me out to what am I missing?</p>