title: How XSLT generate a dynamic variable array from XML?
body: <p>I am using XSLT to transform XML to HTML. Currently i am trying to figured out how can i make an array variable in XSLT.</p>
  
  <p><strong>This is my XML :</strong> </p>
  
  <pre><code>&lt;data&gt;
      &lt;ACCOUNTS elem="0"&gt;
          &lt;ACCOUNT_NO&gt;12345&lt;/ACCOUNT_NO&gt;
      &lt;/ACCOUNTS&gt;
      &lt;ACCOUNTS elem="1"&gt;
          &lt;ACCOUNT_NO&gt;67890&lt;/ACCOUNT_NO&gt;
      &lt;/ACCOUNTS&gt;
  &lt;/data&gt;
  </code></pre>
  
  <p><strong>This is my the XSLT that i try to figured out but is not working :</strong></p>
  
  <pre><code>&lt;xsl:variable name="accounts"&gt;
      &lt;xsl:for-each select="data/ACCOUNTS"&gt;
          &lt;child elem="&lt;xsl:value-of select='position()' /&gt;"&gt;&lt;xsl:value-of select="ACCOUNT_NO" /&gt;&lt;/child&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p><strong>How can i add the position into the XML node so that i'm able to display it out by using</strong></p>
  
  <pre><code>&lt;xsl:value-of select="$account[@elem=1]" /&gt;
  </code></pre>
  
  <p>Please help me and let me know if got any concern. Thanks.</p>
  
  <p><strong>UPDATED :</strong></p>
  
  <p><strong>My full XSLT code :</strong></p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="html" encoding="utf-8" indent="yes"/&gt;
  
  &lt;xsl:variable name="accounts"&gt;
      &lt;xsl:for-each select="data/ACCOUNTS"&gt;
          &lt;child elem="{@elem}"&gt;&lt;xsl:value-of select="ACCOUNT_NO" /&gt;&lt;/child&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:variable&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;html&gt;
          &lt;head&gt;&lt;title&gt;testing&lt;/title&gt;&lt;/head&gt;
          &lt;body&gt;
              &lt;xsl:value-of select="$accounts/child[@elem='0']" /&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>And when i compile i get this error :</strong> </p>
  
  <pre><code>JAXPSAXProcessorInvoker  - Error checking type of the expression 'FilterParentPath(variable-ref(accounts/result-tree), step("child", 40, pred(=(step("attribute", 18), literal-expr(0)))))'.
  </code></pre>