title: How to branch properly in XSLT?
body: <p>I am trying to branch in XSLT. Here is the run down of what I am trying to do:</p>
  
  <p>I am traversing through an XML file and searching for a value that has matching Section2, Section3, and Section4 (Section 1 and 5 are just used for processing purposes). If all the values match I will print out the corresponding Section5 and then be done with processing.</p>
  
  <p>The issue I am having is if I do not find the three matching sections, for example if I find Section2 and Section3 but not Section4 I need to go back through Section4 and search for a section with value '#'. If I find Section2 and not Section3 I will go back through Section3 search for a '#' then I will go to Secton4 and search for the correct value (If I do not find it I will look for a '#').</p>
  
  <p>I have no idea how to achieve the above functionality. Currently all the code is doing is finding the matching values but it is not handling the pound case described above, any help will be greatly appreciated.</p>
  
  <p>I have included the XSLT below and the XML section below.</p>
  
  <pre><code>&lt;xsl:template match="Section1"&gt;
      &lt;xsl:param name="sec2"/&gt;
      &lt;xsl:param name="sec3"/&gt;
      &lt;xsl:param name="sec4"/&gt;
      &lt;xsl:apply-templates select="Section2[./@value=$sec2]"&gt;
          &lt;xsl:with-param name="sec3" select="$sec3"/&gt;
          &lt;xsl:with-param name="sec4" select="$sec4"/&gt;
      &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="Section2"&gt;
      &lt;xsl:param name="sec3"/&gt;
      &lt;xsl:param name="sec4"/&gt;
      &lt;xsl:apply-templates select="Section3[./@value=$sec3]"&gt;
          &lt;xsl:with-param name="sec4" select="$sec4"/&gt;
      &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="Section3"&gt;
      &lt;xsl:param name="sec4"/&gt;
      &lt;xsl:apply-templates select="Section4[./@value=$sec4]"/&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="Section4"&gt;
      &lt;xsl:apply-templates select="Content"/&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="Section5"&gt;
      &lt;!--Value will be printed here--&gt;
  &lt;/xsl:template&gt;
  
  &lt;Section1&gt;
  &lt;Section2 value="AP"&gt;
      &lt;Section3 value="JP"&gt;
          &lt;Section4 value="true"&gt;
              &lt;Section5&gt;Content #1&lt;/Section5&gt;
          &lt;/Section4&gt;
          &lt;Section4 value="false"&gt;
              &lt;Section5&gt;Content #2&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
      &lt;Section3 value="KO"&gt;
          &lt;Section4 value="true"&gt;
              &lt;Section5&gt;Content #3&lt;/Section5&gt;
          &lt;/Section4&gt;
          &lt;Section4 value="false"&gt;
              &lt;Section5&gt;Content #4&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
      &lt;Section3 value="#"&gt;
          &lt;Section4 value="true"&gt;
              &lt;Section5&gt;Content #5&lt;/Section5&gt;
          &lt;/Section4&gt;
          &lt;Section4 value="false"&gt;
              &lt;Section5&gt;Content #6&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
  &lt;/Section2&gt;
  &lt;Section2 value="LA"&gt;
      &lt;Section3 value="#"&gt;
          &lt;Section4 value="true"&gt;
              &lt;Section5&gt;Content #7&lt;/Section5&gt;
          &lt;/Section4&gt;
          &lt;Section4 value="false"&gt;
              &lt;Section5&gt;Content #8&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
  &lt;/Section2&gt;
  &lt;Section2 value="NA"&gt;
      &lt;Section3 value="#"&gt;
          &lt;Section4 value="true"&gt;
              &lt;Section5&gt;Content #9&lt;/Section5&gt;
          &lt;/Section4&gt;
          &lt;Section4 value="false"&gt;
              &lt;Section5&gt;Content #10&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
  &lt;/Section2&gt;
  &lt;Section2 value="E"&gt;
      &lt;Section3 value="#"&gt;
          &lt;Section4 value="#"&gt;
              &lt;Section5&gt;Content #11&lt;/Section5&gt;
          &lt;/Section4&gt;
      &lt;/Section3&gt;
  &lt;/Section2&gt;
  </code></pre>
  
  <p></p>