title: XSLT 1.0 count and then copy structure where child ends-with
body: <p>I have to copy all the sets where the mail end with "test.com", if there count is greater than 5. I've tried several things, but nothing seems to work.</p>
  
  <p>How can I do this with xslt 1.0?</p>
  
  <pre><code>&lt;root&gt;
      &lt;sets&gt;
          &lt;set&gt;
              &lt;mail&gt;a@test.com&lt;/mail&gt;
              &lt;foo/&gt;
          &lt;/set&gt;
          &lt;set&gt;
              &lt;mail&gt;a@test.net&lt;/mail&gt;
              &lt;foo/&gt;
          &lt;/set&gt;
          &lt;set&gt;
              &lt;mail&gt;b@test.com&lt;/mail&gt;
              &lt;foo/&gt;
          &lt;/set&gt;
      &lt;/sets&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>For example I tried this:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="/"&gt;
      &lt;xsl:if test="count(/root/sets/set[mail = '*test.com'])"&gt;
          &lt;root&gt;
              &lt;sets&gt;
                  &lt;xsl:for-each select="/root/sets/set"&gt;
                      &lt;xsl:if test="contains(./mail, 'test.com')"&gt;
                          &lt;xsl:copy-of select="./*"/&gt;
                      &lt;/xsl:if&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/sets&gt;
          &lt;/root&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>