title: Why does XSLT template not get applied?
body: <p>I have some XML that represents two alternative versions of some text and I am using XSLT to perform the modification that selects one or other versions. In addition, one alternative also contains a placeholder that should be replaced with some other bit of text.</p>
  
  <p>The XSLT is generated programmatically and is essentially an identity transformation with a couple of extra templates that perform the necessary tweaks. However, when the XSLT matches the alternative with the placeholder, the placeholder template doesn't get applied and is never filled in.</p>
  
  <p>The actual code uses python's lxml, but I have been mostly testing the XSLT in notepad++ with the XML plugin. The plugin uses libxml2 and libxslt, like lxml, so they shouldn't be any different.</p>
  
  <p>I have tried adding various versions of <code>&lt;xsl:apply-template /&gt;</code> into template 2, but nothing results in the placeholder getting the value that I expect</p>
  
  <p>The following is a very cut down version of the XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;sn:text xmlns:sn="http://some.namespace" xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;p&gt;
      &lt;sn:alts sn:id="alts_1"&gt;
        &lt;sn:alt sn:id="alt_1"&gt;start 1&lt;/sn:alt&gt;
        &lt;sn:alt sn:id="alt_2"&gt;
          &lt;sn:placeholder sn:id="p_1"/&gt; start 2&lt;/sn:alt&gt;
      &lt;/sn:alts&gt; blah blah blah...&lt;/p&gt;
  &lt;/sn:text&gt;
  </code></pre>
  
  <p>And the following is the generated XSLT:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:sn="http://some.namespace"&gt;
    &lt;!--template 1--&gt;
    &lt;xsl:template match="sn:placeholder[@sn:id='p_1']"&gt;XYZ&lt;/xsl:template&gt;
    &lt;!--template 2--&gt;
    &lt;xsl:template match="sn:alts[@sn:id='alts_1']"&gt;
      &lt;xsl:value-of select="sn:alt[@sn:id='alt_2']" /&gt;
    &lt;/xsl:template&gt;
    &lt;!--identity transform--&gt;
    &lt;xsl:template match="*"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="@*|text()|comment()|processing-instruction"&gt;
      &lt;xsl:copy-of select="."/&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The result that I am expecting should be something like:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;sn:text xmlns:sn="http://some.namespace" xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;p&gt;XYZ start 2 blah blah blah...&lt;/p&gt;
  &lt;/sn:text&gt;
  </code></pre>
  
  <p>Instead, the placeholder is not replaced with "XYZ", but is left out completely:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;sn:text xmlns:sn="http://some.namespace" xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;p&gt; start 2 blah blah blah...&lt;/p&gt;
  &lt;/sn:text&gt;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Thanks for the pointers. It was quite obvious in the end:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:sn="http://some.namespace"&gt;
    &lt;xsl:strip-space elements="*"/&gt;
    &lt;xsl:output method="xml" indent="yes" /&gt;
    &lt;!--template 1--&gt;
    &lt;xsl:template match="sn:placeholder[@sn:id='p_1']"&gt;XYZ&lt;/xsl:template&gt;
    &lt;!--template 2--&gt;
    &lt;xsl:template match="sn:alts[@sn:id='alts_1']"&gt;
      &lt;xsl:apply-templates select="sn:alt/sn:placeholder"/&gt;
      &lt;xsl:value-of select="sn:alt[@sn:id='alt_1']" /&gt;
    &lt;/xsl:template&gt;
    &lt;!--identity transform--&gt;
    &lt;xsl:template match="*"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="@*|text()|comment()|processing-instruction()"&gt;
      &lt;xsl:copy-of select="."/&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>