title: Renaming duplicate array names in XSLT 1.0
body: <p>I have below list with arrays having same name(json:array name=&quot;member&quot;). I am trying to rename them something meaningful (json:array name=&quot;member1&quot;) so they remain unique values. I am trying to use identity template.</p>
  <p>Input:</p>
  <pre><code>&lt;json:object xmlns:json=&quot;http://www.ibm.com/xmlns/prod/2009/jsonx&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
     &lt;json:array xmlns:dpfunc=&quot;http://www.datapower.com/extensions/functions&quot; xmlns:str=&quot;http://exslt.org/strings&quot; name=&quot;benefits&quot;&gt;
        &lt;json:object&gt;
           &lt;json:string name=&quot;ArrayCode&quot;&gt;A&lt;/json:string&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-001&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-002&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-003&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
        &lt;/json:object&gt;
        &lt;json:object&gt;
           &lt;json:string name=&quot;ArrayCode&quot;&gt;B&lt;/json:string&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-001&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-002&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-003&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
        &lt;/json:object&gt;
     &lt;/json:array&gt;
  &lt;/json:object&gt;
  </code></pre>
  <p>Expected Output:</p>
  <pre><code>   &lt;json:object xmlns:json=&quot;http://www.ibm.com/xmlns/prod/2009/jsonx&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
     &lt;json:array xmlns:dpfunc=&quot;http://www.datapower.com/extensions/functions&quot; xmlns:str=&quot;http://exslt.org/strings&quot; name=&quot;benefits&quot;&gt;
        &lt;json:object&gt;
           &lt;json:string name=&quot;ArrayCode&quot;&gt;A&lt;/json:string&gt;
           &lt;json:array name=&quot;member1&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-001&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member2&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-002&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member3&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;A-003&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
        &lt;/json:object&gt;
        &lt;json:object&gt;
           &lt;json:string name=&quot;ArrayCode&quot;&gt;B&lt;/json:string&gt;
           &lt;json:array name=&quot;member1&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-001&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member2&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-002&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
           &lt;json:array name=&quot;member3&quot;&gt;
              &lt;json:object&gt;
                 &lt;json:string name=&quot;memberID&quot;&gt;B-003&lt;/json:string&gt;
              &lt;/json:object&gt;
           &lt;/json:array&gt;
        &lt;/json:object&gt;
     &lt;/json:array&gt;
  &lt;/json:object&gt;
  </code></pre>
  <p>XSLT I tried with Identity template and for-each to loop through array list.</p>
  <pre><code>&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:date=&quot;http://exslt.org/dates-and-times&quot; xmlns:dp=&quot;http://www.datapower.com/extensions&quot; xmlns:dpfunc=&quot;http://www.datapower.com/extensions/functions&quot; xmlns:fn=&quot;http://www.w3.org/2005/xpath-functions&quot; xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot; xmlns:json=&quot;http://www.ibm.com/xmlns/prod/2009/jsonx&quot; xmlns:str=&quot;http://exslt.org/strings&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; version=&quot;1.0&quot; xsi:schemaLocation=&quot;http://www.datapower.com/schemas/json jsonx.xsd&quot; extension-element-prefixes=&quot;dp&quot; exclude-result-prefixes=&quot;xsl fo xs fn dp date&quot;&gt;
     
     &lt;xsl:template match=&quot;@* | node()&quot;&gt;
        &lt;xsl:copy&gt;
           &lt;xsl:apply-templates select=&quot;@* | node()&quot;/&gt;
        &lt;/xsl:copy&gt;
     &lt;/xsl:template&gt;
     
     
     &lt;xsl:template match=&quot;json:array/@name&quot;&gt;
        &lt;xsl:for-each select=&quot;json:object/json:array&quot;&gt;
           &lt;xsl:attribute name=&quot;@name{position()}&quot;&gt;
              &lt;xsl:value-of select=&quot;@name&quot;/&gt;
           &lt;/xsl:attribute&gt;
        &lt;/xsl:for-each&gt;  
     &lt;/xsl:template&gt;
     
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>No change is happening to input with above code. I guess using for-each is wrong here. But how can I reach array names nested inside.</p>