title: XSLT: Simulating a template match inside a variable
body: <p><strong>I would like to know how can I simulate a template mach inside a variable based on the code below.</strong></p>
  
  <p><em>The output of this XSLT code I would like to store it in a variable and use it later in the script:</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes"/&gt;
  
    &lt;xsl:template match="*"&gt;
      &lt;xsl:element name="{local-name(.)}"&gt;
        &lt;xsl:apply-templates select="@* | node()"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="@*"&gt;
      &lt;xsl:attribute name="{local-name(.)}"&gt;
        &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I can achieve this now by using 2 XSLT scripts but I would like only to use one script.</p>
  
  <p>The XSLT script should give the same output like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes"/&gt;
  
    &lt;xsl:variable name="InputNew"&gt;
    &lt;xsl:template match="*"&gt;
      &lt;xsl:element name="{local-name(.)}"&gt;
        &lt;xsl:apply-templates select="@* | node()"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="@*"&gt;
      &lt;xsl:attribute name="{local-name(.)}"&gt;
        &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:template&gt;
    &lt;/xsl:variable&gt;
  
    &lt;xsl:template match="/"&gt;
       &lt;xsl:copy-of select="$InputNew"/&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>I know I can't use a template match inside a variable, I can only use call-template but I am unable to do the right XSLT code for this.</strong></p>
  
  <p><em><strong>EDIT: Here is the working script:</em></strong></p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsl soap xsi"&gt;
  &lt;xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes" omit-xml-declaration="yes"/&gt;
     &lt;xsl:strip-space elements="*"/&gt;
  
      &lt;xsl:template match ="*" mode="stripNs"&gt;
          &lt;xsl:element name ="{local-name()}" &gt;
              &lt;xsl:apply-templates select ="@* | node()" mode="stripNs"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;xsl:variable name="noNamespaces"&gt;
         &lt;xsl:apply-templates select="soap:Envelope/soap:Body/*" mode="stripNs" /&gt;
      &lt;/xsl:variable&gt;
  
      &lt;xsl:template match="/"&gt;
         &lt;!-- Now I can do what I want with the variable $noNamespaces --&gt;
         &lt;xsl:copy-of select="$noNamespaces"/&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>