title: Remove an XML element containing an xmlns attribute
body: <p>I want to remove the element (the wrapper - not it descendants) called "searchBookResponse" from an XML file using XSLT.</p>
  
  <p>When the "searchBookResponse" element has no attributes or non "xmlns" attributes, my XSLT code works just fine.
  However, with these xmlns attributes, it is not working anymore.</p>
  
  <p>This is the input XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;books&gt;
    &lt;searchBookResponse xmlns="urn:example.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;book&gt;
        &lt;author&gt;Tom&lt;/author&gt;
        &lt;title&gt;Test&lt;/title&gt;
      &lt;/book&gt;
      &lt;book&gt;
        &lt;author&gt;David&lt;/author&gt;
        &lt;title&gt;Test two&lt;/title&gt;
      &lt;/book&gt;
    &lt;/searchBookResponse&gt;
    &lt;book&gt;
      &lt;author&gt;Anas&lt;/author&gt;
      &lt;title&gt;Test two&lt;/title&gt;
    &lt;/book&gt;
    &lt;book&gt;
      &lt;author&gt;Jim&lt;/author&gt;
      &lt;title&gt;Test two&lt;/title&gt;
    &lt;/book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>And this is the XSL Stylesheet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="node() | @*"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="node() | @*" /&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="@xmlns" /&gt;
  
  
    &lt;xsl:template match="searchBookResponse"&gt;
        &lt;xsl:apply-templates select="node()" /&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>When applied, the output XML file is just the same as the input XML file. Must I apply some string pattern matching for removing the xmlns attribute first and then removing the actual element?
  I want to achieve something like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;books&gt;
          &lt;book&gt;
            &lt;author&gt;Tom&lt;/author&gt;
            &lt;title&gt;Test&lt;/title&gt;
          &lt;/book&gt;
          &lt;book&gt;
            &lt;author&gt;David&lt;/author&gt;
            &lt;title&gt;Test two&lt;/title&gt;
          &lt;/book&gt;
        &lt;book&gt;
          &lt;author&gt;Anas&lt;/author&gt;
          &lt;title&gt;Test two&lt;/title&gt;
        &lt;/book&gt;
        &lt;book&gt;
          &lt;author&gt;Jim&lt;/author&gt;
          &lt;title&gt;Test two&lt;/title&gt;
        &lt;/book&gt;
      &lt;/books&gt;
  </code></pre>
  
  <h2>-----------------------------------------------------------------</h2>
  
  <p>Ok, Tim and Michael provided me with a correct answer. But now I have extended the orginal document as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soapenv:Body&gt;
      &lt;LibrarySearchResponse xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch"&gt;
        &lt;tns:query/&gt;
        &lt;tns:books&gt;
          &lt;searchBooksResponse xmlns="urn:soft.vub.ac.be/" xmlns:xsd="http://www.w3.org/2001/
  XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:book&gt;
              &lt;tns:author&gt;Robert Ludlum&lt;/tns:author&gt;
              &lt;tns:isbn&gt;95248457&lt;/tns:isbn&gt;
              &lt;tns:publicationDate&gt;2004-01-01T00:00:00Z&lt;/tns:publicationDate&gt;
              &lt;tns:publisher&gt;Orion&lt;/tns:publisher&gt;
              &lt;tns:title&gt;The Bourne Identity&lt;/tns:title&gt;
            &lt;/tns:book&gt;
            &lt;tns:book&gt;
              &lt;tns:author&gt;Douglas Adams&lt;/tns:author&gt;
              &lt;tns:isbn&gt;345453743&lt;/tns:isbn&gt;
              &lt;tns:publicationDate&gt;2002-01-01T00:00:00Z&lt;/tns:publicationDate&gt;
              &lt;tns:publisher&gt;Del Rey&lt;/tns:publisher&gt;
              &lt;tns:title&gt;The Ultimate Hitchhiker's Guide to the Galaxy&lt;/tns:title&gt;
            &lt;/tns:book&gt;
            &lt;tns:book&gt;
              &lt;tns:author&gt;William Sleator&lt;/tns:author&gt;
              &lt;tns:isbn&gt;810993562&lt;/tns:isbn&gt;
              &lt;tns:publicationDate&gt;2008-01-01T00:00:00Z&lt;/tns:publicationDate&gt;
              &lt;tns:publisher&gt;Amulet Books&lt;/tns:publisher&gt;
              &lt;tns:title&gt;Test&lt;/tns:title&gt;
            &lt;/tns:book&gt;
            &lt;tns:book&gt;
              &lt;tns:author&gt;Jordan Belfort&lt;/tns:author&gt;
              &lt;tns:isbn&gt;606259090&lt;/tns:isbn&gt;
              &lt;tns:publicationDate&gt;2008-01-01T00:00:00Z&lt;/tns:publicationDate&gt;
              &lt;tns:publisher&gt;Hodder Paperback&lt;/tns:publisher&gt;
              &lt;tns:title&gt;The Wolf of Wall Street&lt;/tns:title&gt;
            &lt;/tns:book&gt;
          &lt;/searchBooksResponse&gt;
          &lt;tns:book xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://library.be"
          xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:author&gt;James, E. L.&lt;/tns:author&gt;
            &lt;tns:isbn&gt;0345803485&lt;/tns:isbn&gt;
            &lt;tns:publicationDate&gt;3914-01-10T23:00:00.000Z&lt;/tns:publicationDate&gt;
            &lt;tns:publisher&gt;Vintage Books&lt;/tns:publisher&gt;
            &lt;tns:title&gt;50 Shades of Grey&lt;/tns:title&gt;
          &lt;/tns:book&gt;
          &lt;tns:book xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://library.be"
          xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:author&gt;James Dashner&lt;/tns:author&gt;
            &lt;tns:isbn&gt;0385388896&lt;/tns:isbn&gt;
            &lt;tns:publicationDate&gt;3914-04-20T22:00:00.000Z&lt;/tns:publicationDate&gt;
            &lt;tns:publisher&gt;The Maze Runner Series&lt;/tns:publisher&gt;
            &lt;tns:title&gt;Test&lt;/tns:title&gt;
          &lt;/tns:book&gt;
          &lt;tns:book xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://library.be"
          xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:author&gt;William Sleator&lt;/tns:author&gt;
            &lt;tns:isbn&gt;0810993562&lt;/tns:isbn&gt;
            &lt;tns:publicationDate&gt;3908-03-31T22:00:00.000Z&lt;/tns:publicationDate&gt;
            &lt;tns:publisher&gt;Amulet Books&lt;/tns:publisher&gt;
            &lt;tns:title&gt;Test&lt;/tns:title&gt;
          &lt;/tns:book&gt;
          &lt;tns:book xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://library.be"
          xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:author&gt;Douglas Adams&lt;/tns:author&gt;
            &lt;tns:isbn&gt;0345453743&lt;/tns:isbn&gt;
            &lt;tns:publicationDate&gt;3902-05-29T22:00:00.000Z&lt;/tns:publicationDate&gt;
            &lt;tns:publisher&gt;Del Rey&lt;/tns:publisher&gt;
            &lt;tns:title&gt;The Ultimate Hitchhiker's Guide to the Galaxy&lt;/tns:title&gt;
          &lt;/tns:book&gt;
          &lt;tns:book xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://library.be"
          xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;tns:author&gt;Michalewicz, Zbigniew Fogel, David B.&lt;/tns:author&gt;
            &lt;tns:isbn&gt;9783642061349&lt;/tns:isbn&gt;
            &lt;tns:publicationDate&gt;3912-10-31T23:00:00.000Z&lt;/tns:publicationDate&gt;
            &lt;tns:publisher&gt;Del Rey&lt;/tns:publisher&gt;
            &lt;tns:title&gt;How to Solve It: Modern Heuristics&lt;/tns:title&gt;
          &lt;/tns:book&gt;
        &lt;/tns:books&gt;
      &lt;/LibrarySearchResponse&gt;
    &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>I still wanted to remove the <code>searchBookResponse</code> element (the wrapper), but I get the following error: <code>"The source document is in namespace http://schemas.xmlsoap.org/soap/envelope/, but none of the template rules match elements in this namespace."</code></p>
  
  <p>However, when I shorten the document like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soapenv:Body&gt;
      &lt;LibrarySearchResponse xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch"&gt;
        &lt;books&gt;
          &lt;searchBookResponse xmlns="urn:soft.vub.ac.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;book&gt;
              &lt;author&gt;Tom&lt;/author&gt;
              &lt;title&gt;Test one&lt;/title&gt;
            &lt;/book&gt;
            &lt;book&gt;
              &lt;author&gt;David&lt;/author&gt;
              &lt;title&gt;Test two&lt;/title&gt;
            &lt;/book&gt;
          &lt;/searchBookResponse&gt;
          &lt;book xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nl="http://library.be" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;author&gt;James, E. L.&lt;/author&gt;
            &lt;title&gt;50 Shades of Grey&lt;/title&gt;
          &lt;/book&gt;
        &lt;/books&gt;
      &lt;/LibrarySearchResponse&gt;
    &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>The <code>searchBookResponse</code> element - the wrapper, is removed, no error messages are displayed and the output is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soapenv:Body&gt;
        &lt;LibrarySearchResponse xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch"&gt;
           &lt;books&gt;
              &lt;book xmlns=""&gt;
                 &lt;author&gt;Tom&lt;/author&gt;
                 &lt;title&gt;Test one&lt;/title&gt;
              &lt;/book&gt;
              &lt;book xmlns=""&gt;
                 &lt;author&gt;David&lt;/author&gt;
                 &lt;title&gt;Test two&lt;/title&gt;
              &lt;/book&gt;
              &lt;book xmlns="http://library.be"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:nl="http://library.be"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
                 &lt;author&gt;James, E. L.&lt;/author&gt;
                 &lt;title&gt;50 Shades of Grey&lt;/title&gt;
              &lt;/book&gt;
           &lt;/books&gt;
        &lt;/LibrarySearchResponse&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Using this stylesheet:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ns1="urn:soft.vub.ac.be"&gt;
  
    &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
    &lt;xsl:strip-space elements="*"/&gt;
  
    &lt;!-- identity transform --&gt;
    &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="ns1:searchBookResponse" &gt;
      &lt;xsl:apply-templates select="*" mode="remove-namespace"/&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="remove-namespace"&gt;
      &lt;xsl:element name="{local-name()}"&gt;
        &lt;xsl:copy-of select="@*"/&gt;
        &lt;xsl:apply-templates select="@*|node()" mode="remove-namespace"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Must I declare more namespaces and match each one of them? How comes that the shortened version works fine and the original, full version doesn't?</p>
  
  <p>Thanks in advance!</p>