title: XSLT - How to get distinct element names from XML?
body: <p>I would like to get the distinct element names from my XML file using XSLT-1.0.</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;forms&gt;
    &lt;form1&gt;
         &lt;metadata&gt;
           &lt;c1&gt;some value&lt;/c1&gt;
           &lt;c2&gt;some value&lt;/c2&gt;
         &lt;/metadata&gt;
         &lt;set&gt;
           &lt;subset1&gt;
               &lt;c3&gt;some value&lt;/c3&gt;
               &lt;c4&gt;some value&lt;/c4&gt;
               &lt;c5&gt;some value&lt;/c5&gt;
           &lt;/subset1&gt;
           &lt;subset2&gt;
               &lt;c3&gt;some value&lt;/c3&gt;
               &lt;c4&gt;some value&lt;/c4&gt;
               &lt;c6&gt;some value&lt;/c6&gt;
           &lt;/subset2&gt;
         &lt;/set&gt;               
    &lt;/form1&gt;
    &lt;form2&gt;
     ...
    &lt;/form2&gt;
  &lt;/forms&gt;
  </code></pre>
  
  <p>My output should look like below when I pass the form name to the XSLT. For example, if I pass "form1" it should get me the distinct data elements available inside my <code>&lt;form1&gt;</code> tag like this:</p>
  
  <blockquote>
    <p>c1, c2, c3, c4, c5, c6</p>
  </blockquote>
  
  <p>Also, I tried this XSLT and its returning this:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="text"/&gt;
  
    &lt;xsl:template match="/"&gt;
      &lt;xsl:for-each select=
     "//*/*/*[not(../following::*/*
                         [not(name() = name(current()))]
                 )
             ]"&gt;
        &lt;xsl:value-of select="concat(name(), ' ')"/&gt;
      &lt;/xsl:for-each&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>set1, set2, subset1, subset2, c3, c4, c6</p>
  </blockquote>
  
  <p>Expected output:</p>
  
  <blockquote>
    <p>c1, c2, c3, c4, c5, c6</p>
  </blockquote>
  
  <p>Also, how to pass my form name (i.e. <code>form1</code>) to my XSLT?</p>