title: How do I delete an Element with a Sub-Element having a Specific Text with XSLT
body: <p>I want to use XSLT to delete an element which has a specific sub-element which has a specific text. Use case: I want to remove a plugin from a Mavon pom.xml file.</p>
  
  <p>Assume the following XML of the (abridged) Maven pom.xml:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;X&lt;/groupId&gt;
    &lt;artifactId&gt;Y&lt;/artifactId&gt;
    &lt;version&gt;0.8.5-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;Y&lt;/name&gt;
    &lt;description&gt;Y.&lt;/description&gt;
  
    &lt;build&gt;
      &lt;resources&gt;
        &lt;resource&gt;
          &lt;directory&gt;src/main/resources&lt;/directory&gt;
          &lt;filtering&gt;true&lt;/filtering&gt;
        &lt;/resource&gt;
      &lt;/resources&gt;
  
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
            &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
            &lt;configuration&gt;
              &lt;lifecycleMappingMetadata&gt;
                &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[1.0.0,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;enforce&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;ignore /&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                &lt;/pluginExecutions&gt;
              &lt;/lifecycleMappingMetadata&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  
      &lt;plugins&gt;
  
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.9.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;show&gt;private&lt;/show&gt;
            &lt;detectLinks&gt;true&lt;/detectLinks&gt;
            &lt;detectJavaApiLink&gt;true&lt;/detectJavaApiLink&gt;
            &lt;quiet&gt;true&lt;/quiet&gt;
          &lt;/configuration&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;attach-javadoc&lt;/id&gt;
              &lt;goals&gt;
                &lt;goal&gt;jar&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
  
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;shade&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
  
                &lt;createSourcesJar&gt;true&lt;/createSourcesJar&gt;
                &lt;shadeTestJar&gt;true&lt;/shadeTestJar&gt;
                &lt;minimizeJar&gt;false&lt;/minimizeJar&gt;
                &lt;shadedArtifactAttached&gt;true&lt;/shadedArtifactAttached&gt;
                &lt;createDependencyReducedPom&gt;false&lt;/createDependencyReducedPom&gt;
  
                &lt;shadedClassifierName&gt;full&lt;/shadedClassifierName&gt;
  
                &lt;filters&gt;
                  &lt;filter&gt;
                    &lt;artifact&gt;*:*&lt;/artifact&gt;
                    &lt;excludes&gt;
                      &lt;exclude&gt;META-INF/*.SF&lt;/exclude&gt;
                      &lt;exclude&gt;META-INF/*.DSA&lt;/exclude&gt;
                      &lt;exclude&gt;META-INF/*.RSA&lt;/exclude&gt;
                    &lt;/excludes&gt;
                  &lt;/filter&gt;
                &lt;/filters&gt;
  
  
                &lt;transformers&gt;
                  &lt;transformer
                    implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" /&gt;
                  &lt;transformer
                    implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" /&gt;
                  &lt;transformer
                    implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer" /&gt;
                  &lt;transformer
                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /&gt;
                &lt;/transformers&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
  
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>How can I delete the <code>maven-shade-plugin</code> plugin? This means I need to delete the <code>plugin</code> node which has a child node named <code>artifactId</code> (which may be the first, second, or nth child) which has the text <code>maven-shade-plugin</code>.</p>
  
  <p>This would leave me with the following XML:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;X&lt;/groupId&gt;
    &lt;artifactId&gt;Y&lt;/artifactId&gt;
    &lt;version&gt;0.8.5-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;Y&lt;/name&gt;
    &lt;description&gt;Y.&lt;/description&gt;
  
    &lt;build&gt;
      &lt;resources&gt;
        &lt;resource&gt;
          &lt;directory&gt;src/main/resources&lt;/directory&gt;
          &lt;filtering&gt;true&lt;/filtering&gt;
        &lt;/resource&gt;
      &lt;/resources&gt;
  
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
            &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
            &lt;configuration&gt;
              &lt;lifecycleMappingMetadata&gt;
                &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[1.0.0,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;enforce&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;ignore /&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                &lt;/pluginExecutions&gt;
              &lt;/lifecycleMappingMetadata&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  
      &lt;plugins&gt;
  
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.9.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;show&gt;private&lt;/show&gt;
            &lt;detectLinks&gt;true&lt;/detectLinks&gt;
            &lt;detectJavaApiLink&gt;true&lt;/detectJavaApiLink&gt;
            &lt;quiet&gt;true&lt;/quiet&gt;
          &lt;/configuration&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;attach-javadoc&lt;/id&gt;
              &lt;goals&gt;
                &lt;goal&gt;jar&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
  
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I already read <a href="https://stackoverflow.com/questions/12152519">Removing XML Nodes using XSLT</a> and <a href="https://stackoverflow.com/questions/19055749">Use XSLT/XPATH to select elements having a child element with a specific value</a> and think that something like this will do the trick, but did not yet manage to get it together.</p>
  
  <p>Many thanks.
  Thomas.</p>
  
  <p>P.S.: This question is not about Maven or the best practices thereof, it is about XML/XSLT/XPATH.</p>