title: Prevent XSL loop from printing every value
body: <p>I need to get the <code>servtypes</code> and <code>servamt</code> value when <code>servtypes</code> is equal to "Service 3". I used the XSL logic and it somehow gets the "Service 3" and its corresponding amount. </p>
  
  <p>XSL Code:</p>
  
  <pre><code>&lt;xsl:for-each select="service"&gt;
      &lt;fo:table-row&gt;
          &lt;fo:table-cell padding-left="14pt" display-align="center"&gt;
              &lt;fo:block&gt;
                  &lt;xsl:if test="servtypes='Service 3'"&gt;
                      &lt;xsl:value-of select="servtypes"/&gt;
                  &lt;/xsl:if&gt;
              &lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
          &lt;fo:table-cell text-align="left" &gt;
              &lt;fo:block&gt;
                  &lt;xsl:if test="servtypes='Service 3'"&gt;
                      &lt;xsl:value-of select="servamt"/&gt;
                  &lt;/xsl:if&gt;
              &lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
          &lt;fo:table-cell padding-left="14pt" display-align="center"&gt;
              &lt;fo:block&gt;
                  &lt;fo:leader/&gt;
              &lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
      &lt;/fo:table-row&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>XML Example</p>
  
  <pre><code>&lt;charges&gt;
      &lt;fees&gt;25&lt;/fees&gt;
      &lt;desc&gt;Description&lt;/desc&gt;
      &lt;service&gt;
          &lt;servtypes&gt;Service 1&lt;/servtypes&gt;
          &lt;servamt&gt;150&lt;/servamt&gt;
      &lt;/service&gt;
      &lt;service&gt;
          &lt;servtypes&gt;Service 2&lt;/sertypes&gt;
          &lt;servamt&gt;10&lt;/servamt&gt;
      &lt;/service&gt;
      &lt;service&gt;
          &lt;servtypes&gt;Service 3&lt;/servtypes&gt;
          &lt;servamt&gt;150&lt;/servamt&gt;
      &lt;/service&gt;
  &lt;charges&gt;
  </code></pre>
  
  <p><br>
  The problem is that whenever it loops through different values of service it also creates table row for each service that doesn't match and the cell contains blank values see the table below. 
  <br>
  How do I prevent creation of blank rows and cells and just create a table whose value matches only the Service 3?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt;
  &lt;tr&gt;
   &lt;td&gt;Blank&lt;/td&gt;
   &lt;td&gt;Blank&lt;/td&gt;
   &lt;td&gt;Blank&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Blank&lt;/td&gt;
   &lt;td&gt;Blank&lt;/td&gt;
   &lt;td&gt;Blank&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Service 3&lt;/td&gt;
   &lt;td&gt;Service Value&lt;/td&gt;
   &lt;td&gt;Service&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I was able to make this work check xsl below. <br>
  <strong>Solution</strong></p>
  
  <pre><code>&lt;xsl:for-each select="service"&gt;
      &lt;xsl:if test="servtypes='Service 3'"&gt;
          &lt;fo:table-row&gt;
          &lt;fo:table-cell padding-top="2pt" padding-left="14pt" padding-bottom="2pt" display-align="center"&gt;
              &lt;fo:block&gt;
                  Amount
              &lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
          &lt;fo:table-cell padding-top="2pt" text-align="left" padding-bottom="2pt"&gt;
          &lt;fo:block&gt;
              &lt;xsl:value-of select="servamt"/&gt;
          &lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
          &lt;fo:table-cell padding-top="2pt" padding-left="14pt" padding-bottom="2pt" display-align="center"&gt;
          &lt;fo:block&gt;&lt;fo:leader/&gt;&lt;/fo:block&gt;
          &lt;/fo:table-cell&gt;
          &lt;/fo:table-row&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>