title: XSL FO - Applying templates across namespaces and elements
body: <p>I want to create an xsl fo stylesheet that applies templates conditionally on the namespace of an input xml file AND which reuses as much code as possible while making it possible to access variables throughout the document.</p>
  
  <p>&lt;xsl:template match="CreditNote | Invoice"&gt; seems problematic in the sense that it appears to require the complete layout within, including variables, and cannot be applied across tags.</p>
  
  <p>In my stylesheet I import some definitions:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:n1="bla:bla:CreditNote-2" 
  xmlns:n2="bla:bla:Invoice-2"&gt;
  </code></pre>
  
  <p>The xml files I need to process are in this format:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;CreditNote xsi:schemaLocation="ubla:bla:CreditNote-2 UBL-CreditNote-2.0.xsd"&gt;
  &lt;content&gt;
  </code></pre>
  
  <p>So in this respect I believe I need to use the namespace as my way of determining what to do with the file.</p>
  
  <p>I've experimented a bit with apply-template without much luck.</p>
  
  <p>What I'm looking for is something along these lines:</p>
  
  <pre><code>&lt;apply if namespace is either CreditNote OR Invoice&gt;
   &lt;global variables&gt;
  &lt;/apply&gt;
  
  &lt;apply if namespace is CreditNote&gt;
   bar header
  &lt;/apply&gt;
  
  &lt;apply if namespace is Invoice&gt;
   foo header
  &lt;/apply&gt;
  
  &lt;apply if namespace is either CreditNote OR Invoice&gt;
   common body
  &lt;/apply&gt;
  
  &lt;fo:table&gt;
   &lt;fo:table-row&gt;
    &lt;fo:table-cell&gt;
  
      &lt;apply if namespace is CreditNote&gt;
       bar footer
      &lt;/apply&gt;
  
      &lt;apply if namespace is Invoice&gt;
       foo footer $variable
      &lt;/apply&gt;
  
    &lt;/fo:table-cell&gt;
    &lt;fo:table-cell&gt;booya&lt;/fo:table-cell&gt;
   &lt;/fo:table-row&gt;
  &lt;/fo:table&gt;
  </code></pre>