title: How to select all elements between two other elements
body: <p>I want to be able to show all of the  elements that become between other  elements with certain values.
  Eg</p>
  
  <pre><code>&lt;wd&gt;abc&lt;/wd&gt;
  &lt;wd&gt;123&lt;/wd&gt;
  &lt;wd&gt;456&lt;/wd&gt;
  &lt;wd&gt;789&lt;/wd&gt;
  &lt;wd&gt;def&lt;/wd&gt;
  </code></pre>
  
  <p>I want the code to look for all words after abc and before def, and display them.</p>
  
  <p>What I tried so far is (the namespace is ss)</p>
  
  <pre><code>    &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ss="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd"&gt;
  &lt;xsl:output method="text"/&gt;
  
      &lt;xsl:template match="/"&gt;
  
  
  
      &lt;!-- Variable declarations --&gt;
  
      &lt;xsl:variable name="wds" select="//ss:wd"/&gt;
  
      &lt;!-- Variable declarations end--&gt;
  
          &lt;xsl:if test="preceding::ss:wd[contains(.,'7BB')"&gt;
              &lt;xsl:if test="following::ss:wd[contains(.,SHIPMENT)"&gt;
                  &lt;xsl:for-each select="$wds"/&gt;
                  &lt;xsl:value-of select="$wds"/&gt;
              &lt;/xsl:if&gt;
          &lt;/xsl:if&gt;
  
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>But this doesn't work at all. <br>
  How do I get around this?</p>
  
  <p><strong>Update</strong>: In response to Michael</p>
  
  <p>Unless I'm overlooking something, your code should be able to be copied + pasted into mine. However, when I do this, the XSLT executes, but no data is returned.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ss="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd"&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
  
  
  
  &lt;!-- Variable declarations --&gt;
  
  &lt;xsl:variable name="wds" select="//ss:wd"/&gt;
  
  &lt;!-- Variable declarations end--&gt;
  
          &lt;xsl:for-each select="ss:document/ss:wd[preceding-sibling::ss:wd[.='7BB'] and following-sibling::ss:wd[.='SHIPMENT']]"&gt;
              &lt;xsl:value-of select="." /&gt;
              &lt;xsl:if test="position()!=last()"&gt;
                  &lt;xsl:text&gt;/&lt;/xsl:text&gt;  
              &lt;/xsl:if&gt;
          &lt;/xsl:for-each&gt;   
  
  
          Net Amount &lt;xsl:value-of select="$wds[4]"/&gt;
          &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;  
          VAT Amount &lt;xsl:value-of select="$wds[8]"/&gt;
          &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;  
          Total &lt;xsl:value-of select="$wds[12]"/&gt;
  
  
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my entire XSLT so far, I've also attached my source: <a href="https://www.dropbox.com/s/yejumh5ffdkmk8u/POR861896_Order_2014-03-17_0001.xml" rel="nofollow">dropbox</a></p>