title: XSLT - How to speed up a complex for-each
body: <p>I am new to XSLT and i'm having a few speed issues with the following for-each statement. I was hoping someone could give me some pointers as how to optimise this please?</p>
  
  <p>The for-each below is looping through about 4mb of XML. It is testing to ensure that each hotel node has a description and a destination. It is also testing that each hotel has a rating greater than 2 but not 6. The possible values for the rating in the XML are 0, 1, 2, 3, 4, 5 or 6. Ideally i would like it to only select ratings 3, 4 or 5 and ignore the others.</p>
  
  <pre><code>&lt;for-each select="response/results/hotel[
      not(@description = '') and
      @rating &amp;gt; '2' and
      not(@rating = '6') and
      not(@destination = '')              ]"&gt;
    &lt;call-template name="hotelparams"/&gt;
    &lt;call-template name="upropdata"/&gt;
    &lt;call-template name="request"/&gt;
    &lt;call-template name="Newline"/&gt;
  &lt;/for-each&gt;
  </code></pre>
  
  <p>As request I have added the templates that are being called below. The output is creating tab delimited text files which are then imported in mySQL. By the way please ignore the upropdata template, it will be removed shortly...</p>
  
  <pre><code>&lt;xsl:template name="hotelparams"&gt;
  &lt;xsl:value-of select="@itemcode"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of  select="@cheapestcurrency"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@cheapestprice"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@checkin"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@checkout"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@description"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@destair"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@destination"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@destinationid"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@engine"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@hotelname"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@image"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@nights"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@rating"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@resultkey"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@resultno"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@supplierdestination"/&gt;&lt;xsl:value-of select="$tab"/&gt;
  &lt;xsl:value-of select="@type"/&gt;&lt;/xsl:template&gt;
  
  &lt;xsl:template name="upropdata"&gt;
  &lt;xsl:value-of select="$tab"/&gt;\N&lt;xsl:value-of select="$tab"/&gt;\N&lt;xsl:value-of select="$tab"/&gt;\N&lt;xsl:value-of select="$tab"/&gt;\N&lt;xsl:value-of select="$tab"/&gt;\N&lt;xsl:value-of select="$tab"/&gt;2011-01-01&lt;/xsl:template&gt;
  
  &lt;xsl:template name="request"&gt;
  &lt;xsl:for-each select="/response/request/method"&gt;&lt;xsl:value-of select="$tab"/&gt;&lt;xsl:value-of select="./@sessionkey"/&gt;&lt;/xsl:for-each&gt;&lt;/xsl:template&gt;
  &lt;xsl:template name="Newline"&gt;
  &lt;xsl:text&gt;&amp;#13;&lt;/xsl:text&gt;&lt;/xsl:template&gt;
  </code></pre>