title: XSLT 1.0 - How to exclude node trees that do not contain a specific child
body: <p>I've been struggling with this for the last 2 days. I'm nowhere as familiar with XPATH and XSLT as I need to be, but time has not been conducive to truly dig in and study. This is being used in BMC's TrueSight Orchestration application, and as such is limited to using XPATH/XSLT 1.0.</p>
  <p>Some add-on questions that I wouldn't mind being redirected to resources for explanations:</p>
  <ol>
  <li>I'm not familiar with an &quot;identity template&quot; and I have seen it referred to in several posts.</li>
  <li>I'm not familiar with templates with regard to how to be more selective of the elements, nodes, and node sets for processing.
  <ul>
  <li>I'm a shell script programmer by experience, so a top-down approach is a bit foreign to me as it relates to how XML documents are processed.</li>
  </ul>
  </li>
  <li>I'm still learning a lot of the terms, axes, relational paths vs. absolute paths, etc. when it comes to XPATH. I'm not afraid of &quot;Googling&quot; for answers, but sometimes having a go-to resource is better than trying to guess at what keywords might provide a result set that may lead to an answer.
  <ul>
  <li>Is there a more recommended go-to resource? (I know that this is a loaded and biased question, but I'm expecting that there will be a handful of resources that will be more recommended than others.)</li>
  </ul>
  </li>
  </ol>
  <p><strong>I have the following input document:</strong></p>
  <pre><code>&lt;servers&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;CENTRAL&quot; account=&quot;*****&quot; name=&quot;SERVP0001&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseEngineService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Engine Service&lt;/service&gt;
        &lt;service name=&quot;QlikSensePrintingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Printing Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseProxyService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Proxy Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseRepositoryDatabase&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Repository Database&lt;/service&gt;
        &lt;service name=&quot;QlikSenseRepositoryService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Repository Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseSchedulerService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Scheduler Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseServiceDispatcher&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Service Dispatcher&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;SLAVE&quot; account=&quot;*****&quot; name=&quot;SERVP0002&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseEngineService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Engine Service&lt;/service&gt;
        &lt;service name=&quot;QlikSensePrintingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Printing Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseProxyService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Proxy Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseRepositoryService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Repository Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseSchedulerService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Scheduler Service&lt;/service&gt;
        &lt;service name=&quot;QlikSenseServiceDispatcher&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Sense Service Dispatcher&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;NPRINTING&quot; account=&quot;*****&quot; name=&quot;SERVN0001&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikNPrintingEngine&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik NPrinting Engine&lt;/service&gt;
        &lt;service name=&quot;QlikNPrintingLicenseService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik NPrinting License Service&lt;/service&gt;
        &lt;service name=&quot;QlikNPrintingMessagingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;QlikNPrintingMessagingService&lt;/service&gt;
        &lt;service name=&quot;QlikNPrintingRepoService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;QlikNPrintingRepoService&lt;/service&gt;
        &lt;service name=&quot;QlikNPrintingScheduler&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik NPrinting Scheduler&lt;/service&gt;
        &lt;service name=&quot;QlikNPrintingWebEngine&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik NPrinting Web Engine&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>
  <p>I am trying to select from the root element down, including only those service nodes that match either the @name attribute or the text value.</p>
  <p>This is the XSL that I've been able to cobble together through several hours of searching and trial and error. The only part I have not been able to figure out is how to prevent the printing of the server node and its descendants when no matching service is found.</p>
  <pre><code>&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;&gt;
    &lt;xsl:output indent=&quot;no&quot; /&gt;
    &lt;xsl:template match=&quot;node() | @*&quot;&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select=&quot;node() | @*&quot; /&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match=&quot;service&quot;&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test=&quot;contains( translate( normalize-space( ./@name ), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ), translate( normalize-space( &amp;quot;${SERVICENAME}&amp;quot; ), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) )&quot;&gt;
          &lt;xsl:copy-of select=&quot;.&quot; /&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p><strong>This is the current output I'm getting with my XSL:</strong></p>
  <pre><code>&lt;servers&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;CENTRAL&quot; account=&quot;*****&quot; name=&quot;SERVP0001&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;SLAVE&quot; account=&quot;*****&quot; name=&quot;SERVP0002&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;NPRINTING&quot; account=&quot;*****&quot; name=&quot;SERVN0001&quot;&gt;
      &lt;services /&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>
  <p><strong>This is my desired output:</strong></p>
  <pre><code>&lt;servers&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;CENTRAL&quot; account=&quot;*****&quot; name=&quot;SERVP0001&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
    &lt;server os=&quot;WINDOWS&quot; role=&quot;SLAVE&quot; account=&quot;*****&quot; name=&quot;SERVP0002&quot;&gt;
      &lt;services&gt;
        &lt;service name=&quot;QlikLoggingService&quot; start_type=&quot;AUTOMATIC&quot; state=&quot;RUNNING&quot;&gt;Qlik Logging Service&lt;/service&gt;
      &lt;/services&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>
  <p>In some cases, there may be more than one matching service for a server. For example, if I used &quot;engine&quot; as a keyword to match services, I would have 1 match in SERVP0001, 1 match in SERVP0002, and 2 matches in SERVN0001. My provided example output is using the keyword &quot;logging&quot; to match services.</p>
  <p><strong>I know that I do not have a template or Choose-When element that searches for and returns the services whose text values contain my search string.</strong> <em>I figured that if I could get the attribute search to return the correctly formatted document, I could modify to suit for the service text.</em></p>
  <p>Thank you in advance for whatever help and resources you can provide.</p>