title: Using for loop in xslt to traverse over a node
body: <p>I have a xml drafted as follows</p>
  
  <pre><code>&lt;node1&gt;
    &lt;node2&gt;
      &lt;node3&gt;
        val3
      &lt;/node3&gt;
      &lt;node4&gt;
        val4
      &lt;/node4&gt;
      &lt;node5&gt;
       val5
      &lt;/node5&gt;
      &lt;node6&gt;
        val6
      &lt;/node6&gt;
    &lt;/node2&gt;
  &lt;/node1&gt;
  </code></pre>
  
  <p>I m using xslt to loop over <code>&lt;node2&gt;</code>
  now I want to include values only for <code>&lt;node4&gt;</code> and <code>&lt;node5&gt;</code> in the results.
  What Im doing is </p>
  
  <pre><code>&lt;xsl:for-each select="/node1/node2[.= node4 or .= node5]/*&gt;
    &lt;newNode&gt;
      value of selected nodes
    &lt;/newNode&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>have also tried </p>
  
  <pre><code>&lt;xsl:for-each select="/node1/node2[name() = node4 or name() = node5]/*&gt;
        &lt;newNode&gt;
          value of selected nodes
        &lt;/newNode&gt;
      &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&lt;xsl:for-each select="/node1/node2[.name()= node4 or .name()= node5]/*&gt;
        &lt;newNode&gt;
          value of selected nodes
        &lt;/newNode&gt;
      &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>but I m getting values of all the 4 nodes i.e node3, node4, node5 and node6</p>
  
  <p>can any one please put me in the right direction?</p>