title: set selected attribute of html option element within select based on outer for-each index
body: <p>I have a list of items, which I want to iterate through and for each iteration, I would like to create a drop down list and then by default select the item based on the current overall index.</p>
  <p>The example will make it very clear.
  Here's the XML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Plants&gt;
     &lt;Plant PlantId=&quot;13&quot; PlantType=&quot;Tree&quot;/&gt;
     &lt;Plant PlantId=&quot;25&quot; PlantType=&quot;Flower&quot;/&gt;
     &lt;Plant PlantId=&quot;70&quot; PlantType=&quot;Shrub&quot;/&gt;
  &lt;/Plants&gt;
  </code></pre>
  <p>Then I have some XSL:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;&gt;
      &lt;xsl:output method=&quot;html&quot; indent=&quot;yes&quot; encoding=&quot;UTF-8&quot; omit-xml-declaration=&quot;yes&quot;/&gt;
      &lt;xsl:template match=&quot;/&quot;&gt;
          &lt;xsl:param name=&quot;listIdx&quot; select=&quot;0&quot;&gt;
          &lt;/xsl:param&gt;
          &lt;table&gt;
              &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;td&gt;PlantType&lt;/td&gt;
                      &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;xsl:for-each select=&quot;Plants/Plant&quot;&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;select&gt;
                                  &lt;xsl:for-each select=&quot;/Plants/Plant&quot;&gt;
                                      &lt;xsl:element name=&quot;option&quot;&gt;
                                          &lt;xsl:attribute name=&quot;value&quot;&gt;
                                              &lt;xsl:value-of select=&quot;@PlantId&quot;/&gt;
                                          &lt;/xsl:attribute&gt;
                                          &lt;xsl:if test=&quot;count(.) = 2&quot;&gt;
                                              &lt;xsl:attribute name=&quot;selected&quot;&gt;selected&lt;/xsl:attribute&gt;    
                                          &lt;/xsl:if&gt;
                                          &lt;xsl:value-of select=&quot;@PlantType&quot;/&gt;
                                      &lt;/xsl:element&gt;
                                  &lt;/xsl:for-each&gt;
                              &lt;/select&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;        
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>What I get is this:</p>
  <blockquote>
  <p>PlantType<br/>
  Tree [=dropdown with Tree, Flower, Shrub]<br/>
  Tree [=dropdown with Tree, Flower, Shrub]<br/>
  Tree [=dropdown with Tree, Flower, Shrub]<br/></p>
  </blockquote>
  <p>What I'd love to have is:</p>
  <blockquote>
  <p>PlantType<br/>
  Tree   [=dropdown with Tree, Flower, Shrub (idx 1 preselected)]<br/>
  Flower [=dropdown with Tree, Flower, Shrub (idx 2 preselected)]<br/>
  Shrub  [=dropdown with Tree, Flower, Shrub (idx 3 preselected)]<br/></p>
  </blockquote>
  <p>I guess there will be two approaches: 1) use a listIdx in the outer loop (match) and then compare the current index within the inner loop with listIdx. 2) compare inner list index with outer list index on the fly.</p>