title: how to iterate only first level node in xml with x-path?
body: <p>I need to iterate through an XML file. The root node has a few children and I need to either copy the child as is or to do something. So I'm working on an XSLT to do so. Here's a sample source XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;XDSDocumentEntry id="DOC01"&gt;
      &lt;author authorRole="XDSITEST_DICOM_INSTANCE_PUBLISHER" authorPerson="XDSITEST"&gt;Author&lt;/author&gt;
      &lt;classCode displayName="Communication" codingScheme="Connect-a-thon classCodes"&gt;Communication&lt;/classCode&gt;
      &lt;confidentialityCode displayName="Celebrity" codingScheme="Connect-a-thon confidentialityCodes"&gt;
  &lt;/XDSDocumentEntry&gt;
  </code></pre>
  
  <p>In this XML I need to select nodes <strong>author</strong>, <strong>classCode</strong> and <strong>confidentialityCodes</strong> but I'm getting the text() nodes with this code:</p>
  
  <pre><code>        &lt;xsl:for-each select="node()"&gt;&lt;!--&lt;xsl:copy-of select="."/&gt;--&gt;
              &lt;!--&lt;xsl:value-of select="local-name()"/&gt;--&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="author"&gt;
                      do something
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:copy-of select="."/&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>My result so far is this:</p>
  
  <pre><code>author&lt;author authorRole="XDSITEST_DICOM_INSTANCE_PUBLISHER" authorPerson="XDSITEST"
         authorInstitution="Some institution"/&gt;
  classCode&lt;classCode displayName="Communication" codingScheme="Connect-a-thon classCodes"&gt;Communication&lt;/classCode&gt;
  confidentialityCode&lt;confidentialityCode displayName="Celebrity" codingScheme="Connect-a-thon confidentialityCodes"&gt;
  C&lt;/confidentialityCode&gt;
  </code></pre>
  
  <p>Any hint? Thx.</p>
  
  <hr>
  
  <h2>EDIT</h2>
  
  <p>Sorry, had an error (I removed ).</p>
  
  <p>Actually, why am I using the <strong>for-each</strong> is because I need the document exactly as it was except for a few nodes. In the example above the final output should look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;XDSDocumentEntry&gt;
      &lt;author authorRole="XDSITEST_DICOM_INSTANCE_PUBLISHER" authorPerson="XDSITEST"
             authorInstitution="Some institution"/&gt;
      &lt;author&gt;
          &lt;authorInstitution&gt;
              &lt;organizationName&gt;Some institution&lt;/organizationName&gt;
          &lt;/authorInstitution&gt;
          &lt;authorRole&gt;XDSITEST_DICOM_INSTANCE_PUBLISHER&lt;/authorRole&gt;
          &lt;authorPerson&gt;
              &lt;assigningAuthorityName&gt;XDSITEST&lt;/assigningAuthorityName&gt;
          &lt;/authorPerson&gt;
      &lt;/author&gt;
      &lt;classCode displayName="Communication" codingScheme="Connect-a-thon classCodes"&gt;Communication&lt;/classCode&gt;
      &lt;confidentialityCode displayName="Celebrity" codingScheme="Connect-a-thon confidentialityCodes"&gt;
      C&lt;/confidentialityCode&gt;
  &lt;/XDSDocumentEntry&gt;
  </code></pre>
  
  <hr>
  
  <h2>EDIT 2</h2>
  
  <p>I created this template as suggested by @Martin. But still how do I select the node name 'author'??</p>
  
  <pre><code>&lt;xsl:template match="node()|@*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="local-name()=author"&gt;
                      a
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:apply-templates select="node()|@*"/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  </code></pre>