title: how to accumulate the value of position() function in xslt
body: <p>I have this xml file</p>
  
  <pre><code>&lt;netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1"&gt;
      &lt;attribute name="title" value="Vector time series"/&gt;
      &lt;dimension name="time" length="100"/&gt;
      &lt;variable name="time" shape="time" type="double"&gt;
          &lt;attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/&gt;
      &lt;/variable&gt;
      &lt;group name="Vector" tsdsType="Structure" shape="time"&gt;
          &lt;variable name="x" shape="time" type="double"/&gt;
          &lt;variable name="y" shape="time" type="double"/&gt;
          &lt;variable name="z" shape="time" type="double"/&gt;
      &lt;/group&gt;
  &lt;/netcdf&gt;
  </code></pre>
  
  <p>and I need the xslt file which gives the output like this</p>
  
  <pre><code>1.time
  2.Vector
  </code></pre>
  
  <p>which are the name attribute of two tags: variable and group. Currently I have the code like this</p>
  
  <pre><code> &lt;xsl:for-each select="document($path)//*[local-name()='variable']"&gt;
          &lt;xsl:if test="string-length( @*[local-name()='name'] ) &gt;1"&gt;
          &lt;li&gt;
           &lt;xsl:value-of select="position()"/&gt;
          &lt;xsl:value-of select="@*[local-name()='name']"/&gt;
          &lt;/li&gt;
          &lt;/xsl:if&gt;
        &lt;/xsl:for-each&gt;
           &lt;xsl:for-each select="document($path)//*[local-name()='group']"&gt;
          &lt;li&gt;
          &lt;xsl:value-of select="position()"/&gt;
          &lt;xsl:value-of select="@*[local-name()='name']"/&gt;
          &lt;/li&gt;
        &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>and it will give me </p>
  
  <pre><code>1.time
  1.Vector
  </code></pre>
  
  <p>So how can I reach my goal by this position() function or there are any other better way to do this in XSLT? Thanks a lot in advance. </p>