title: How to enumerate indexed (xsl:key) items?
body: <p>I'm new in xml, sorry for the dumb question. I'm trying to create xsl template to convert Source xml to Destination. Actually it's almost done but I don't know how to enumerate <code>&lt;creator&gt;</code>'s correctly (creator@affil in Destination xml).</p>
  
  <p>Source:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;CREATORS&gt;
    &lt;PERSON ROLE="CONTACT"&gt;
      &lt;PREFIX&gt;Prof&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Mike&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS&gt;J&lt;/MIDDLE_INITIALS&gt;
      &lt;LAST_NAME&gt;Petrov&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION&gt;Director&lt;/POSITION&gt;
      &lt;EMAIL_1&gt;pontorez@pontorez.ru&lt;/EMAIL_1&gt;
      &lt;EMAIL_2&gt;webmaster@pontorez.ru&lt;/EMAIL_2&gt;
      &lt;URL&gt;www.pontorez.ru&lt;/URL&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT/&gt;
        &lt;ORGANISATION&gt;Example&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;Finch Pavilion&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2&gt;Middle Way&lt;/ADDRESS_2&gt;
        &lt;CITY&gt;Oxford&lt;/CITY&gt;
        &lt;ZIP&gt;OX9 7LG&lt;/ZIP&gt;
        &lt;REGION/&gt;
        &lt;COUNTRY CODE="GB"&gt;UK&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+380 6245 716300&lt;/PHONE_1&gt;
        &lt;PHONE_2/&gt;
        &lt;FAX_1&gt;+380 6245 716311&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE/&gt;
    &lt;/PERSON&gt;
    &lt;PERSON ID="7091" ROLE="AUTHOR"&gt;
      &lt;PREFIX&gt;Prof&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Mike&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS&gt;J&lt;/MIDDLE_INITIALS&gt;
      &lt;LAST_NAME&gt;Petrov&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION&gt;Director&lt;/POSITION&gt;
      &lt;EMAIL_1&gt;pontorez@pontorez.ru&lt;/EMAIL_1&gt;
      &lt;EMAIL_2&gt;webmaster@pontorez.ru&lt;/EMAIL_2&gt;
      &lt;URL&gt;www.pontorez.ru&lt;/URL&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT/&gt;
        &lt;ORGANISATION&gt;Example&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;Finch Pavilion&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2&gt;Middle Way&lt;/ADDRESS_2&gt;
        &lt;CITY&gt;Oxford&lt;/CITY&gt;
        &lt;ZIP&gt;OX9 7LG&lt;/ZIP&gt;
        &lt;REGION/&gt;
        &lt;COUNTRY CODE="GB"&gt;UK&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+380 6245 716300&lt;/PHONE_1&gt;
        &lt;PHONE_2/&gt;
        &lt;FAX_1&gt;+380 6245 716311&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE&gt;Author footnote&lt;/FOOTNOTE&gt;
    &lt;/PERSON&gt;
    &lt;PERSON ID="7094" ROLE="AUTHOR"&gt;
      &lt;PREFIX&gt;Mrs&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Anne&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS/&gt;
      &lt;LAST_NAME&gt;Spencer&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION/&gt;
      &lt;EMAIL_1&gt;aspencer@Hardware.co.uk&lt;/EMAIL_1&gt;
      &lt;EMAIL_2/&gt;
      &lt;URL/&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT/&gt;
        &lt;ORGANISATION&gt;Example&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;SEO R&amp;amp;D Programme&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2&gt;Finch Pavilion, Middle Way&lt;/ADDRESS_2&gt;
        &lt;CITY&gt;Oxford&lt;/CITY&gt;
        &lt;ZIP&gt;OX9 7LG&lt;/ZIP&gt;
        &lt;REGION&gt;Oxfordshire&lt;/REGION&gt;
        &lt;COUNTRY CODE="GB"&gt;UK&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+380 6245 716300&lt;/PHONE_1&gt;
        &lt;PHONE_2/&gt;
        &lt;FAX_1&gt;+380 6245 716311&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE/&gt;
    &lt;/PERSON&gt;
    &lt;PERSON ID="15756" ROLE="AUTHOR"&gt;
      &lt;PREFIX&gt;Mr&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Ed&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS/&gt;
      &lt;LAST_NAME&gt;Gantos&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION&gt;Senior Medical Statistician&lt;/POSITION&gt;
      &lt;EMAIL_1&gt;santos@xxx.org.uk&lt;/EMAIL_1&gt;
      &lt;EMAIL_2/&gt;
      &lt;URL&gt;http://www.isds.sxo.ac.uk/&lt;/URL&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT&gt;Head of SEO Support&lt;/DEPARTMENT&gt;
        &lt;ORGANISATION&gt;Centre for Statistics in Software&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;Pearson College&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2&gt;Linton Road&lt;/ADDRESS_2&gt;
        &lt;CITY&gt;Oxford&lt;/CITY&gt;
        &lt;ZIP&gt;OX9 6UD&lt;/ZIP&gt;
        &lt;REGION/&gt;
        &lt;COUNTRY CODE="GB"&gt;UK&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+380 6245 112404&lt;/PHONE_1&gt;
        &lt;PHONE_2/&gt;
        &lt;FAX_1&gt;+380 6245 112424&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE/&gt;
    &lt;/PERSON&gt;
    &lt;PERSON ID="7092" ROLE="AUTHOR"&gt;
      &lt;PREFIX&gt;Dr&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Sherry&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS/&gt;
      &lt;LAST_NAME&gt;Wilson&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION/&gt;
      &lt;EMAIL_1&gt;wilson@Hardware.co.uk&lt;/EMAIL_1&gt;
      &lt;EMAIL_2/&gt;
      &lt;URL/&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT/&gt;
        &lt;ORGANISATION&gt;Example&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;SEO R&amp;amp;D Programme&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2&gt;Finch Pavilion, Middle Way&lt;/ADDRESS_2&gt;
        &lt;CITY&gt;Oxford&lt;/CITY&gt;
        &lt;ZIP&gt;OX9 7LG&lt;/ZIP&gt;
        &lt;REGION&gt;Oxfordshire&lt;/REGION&gt;
        &lt;COUNTRY CODE="GB"&gt;UK&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+380 6245 716300&lt;/PHONE_1&gt;
        &lt;PHONE_2/&gt;
        &lt;FAX_1&gt;+380 6245 716311&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE/&gt;
    &lt;/PERSON&gt;
    &lt;GROUP ID="????"&gt;
      &lt;GROUP_NAME&gt;Bond team&lt;/GROUP_NAME&gt;
      &lt;CONTACT_PERSON&gt;Monica Bond&lt;/CONTACT_PERSON&gt;
      &lt;EMAIL_1&gt;mk@Hardware.dk&lt;/EMAIL_1&gt;
      &lt;URL/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT&gt;Nordic Hardware Centre&lt;/DEPARTMENT&gt;
        &lt;ORGANISATION&gt;Creyts, Dept 7512&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;Blegdamsvej 219&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2/&gt;
        &lt;CITY&gt;Copenhagen&lt;/CITY&gt;
        &lt;ZIP&gt;2900&lt;/ZIP&gt;
        &lt;REGION/&gt;
        &lt;COUNTRY CODE="DK"&gt;Denmark&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+415 7667 7110&lt;/PHONE_1&gt;
        &lt;PHONE_2&gt;+415 1234 9429&lt;/PHONE_2&gt;
        &lt;FAX_1&gt;+415 7667 7007&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE&gt;Group footnote&lt;/FOOTNOTE&gt;
    &lt;/GROUP&gt;
    &lt;PERSON ID="3" ROLE="AUTHOR"&gt;
      &lt;PREFIX&gt;Ms&lt;/PREFIX&gt;
      &lt;FIRST_NAME&gt;Monica&lt;/FIRST_NAME&gt;
      &lt;MIDDLE_INITIALS/&gt;
      &lt;LAST_NAME&gt;Bond&lt;/LAST_NAME&gt;
      &lt;SUFFIX/&gt;
      &lt;POSITION&gt;Director of the Hardware Information Management System&lt;/POSITION&gt;
      &lt;EMAIL_1&gt;mk@Hardware.dk&lt;/EMAIL_1&gt;
      &lt;EMAIL_2/&gt;
      &lt;URL&gt;www.cc-ims.net&lt;/URL&gt;
      &lt;MOBILE_PHONE/&gt;
      &lt;ADDRESS&gt;
        &lt;DEPARTMENT&gt;Nordic Hardware Centre&lt;/DEPARTMENT&gt;
        &lt;ORGANISATION&gt;Creyts, Dept 7512&lt;/ORGANISATION&gt;
        &lt;ADDRESS_1&gt;Blegdamsvej 219&lt;/ADDRESS_1&gt;
        &lt;ADDRESS_2/&gt;
        &lt;CITY&gt;Copenhagen&lt;/CITY&gt;
        &lt;ZIP&gt;2900&lt;/ZIP&gt;
        &lt;REGION/&gt;
        &lt;COUNTRY CODE="DK"&gt;Denmark&lt;/COUNTRY&gt;
        &lt;PHONE_1&gt;+415 7667 7110&lt;/PHONE_1&gt;
        &lt;PHONE_2&gt;+415 1234 9429&lt;/PHONE_2&gt;
        &lt;FAX_1&gt;+415 7667 7007&lt;/FAX_1&gt;
        &lt;FAX_2/&gt;
      &lt;/ADDRESS&gt;
      &lt;FOOTNOTE/&gt;
    &lt;/PERSON&gt;
  &lt;/CREATORS&gt;
  </code></pre>
  
  <p>Destination:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;creatorGroup&gt;
    &lt;creator affil="CD004002-aff-0001" creatorRole="author"&gt;
      &lt;forenames&gt;Mike&lt;/forenames&gt;
      &lt;surnamePrefix&gt;J&lt;/surnamePrefix&gt;
      &lt;surname&gt;Petrov&lt;/surname&gt;
      &lt;note id="CD004002-note-0001"&gt;
        &lt;p&gt;Author footnote&lt;/p&gt;
      &lt;/note&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0001" creatorRole="author"&gt;
      &lt;forenames&gt;Anne&lt;/forenames&gt;
      &lt;surname&gt;Spencer&lt;/surname&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0002" creatorRole="author"&gt;
      &lt;forenames&gt;Ed&lt;/forenames&gt;
      &lt;surname&gt;Gantos&lt;/surname&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0001" creatorRole="author"&gt;
      &lt;forenames&gt;Sherry&lt;/forenames&gt;
      &lt;surname&gt;Wilson&lt;/surname&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0003" type="collaboration" creatorRole="author"&gt;
      &lt;collab&gt;Bond team&lt;/collab&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0003" creatorRole="author"&gt;
      &lt;forenames&gt;Monica&lt;/forenames&gt;
      &lt;surname&gt;Bond&lt;/surname&gt;
    &lt;/creator&gt;
    &lt;creator affil="CD004002-aff-0001" creatorRole="contact"&gt;
      &lt;honorifics&gt;Prof&lt;/honorifics&gt;
      &lt;forenames&gt;Mike&lt;/forenames&gt;
      &lt;surnamePrefix&gt;J&lt;/surnamePrefix&gt;
      &lt;surname&gt;Petrov&lt;/surname&gt;
      &lt;jobTitle&gt;Director&lt;/jobTitle&gt;
      &lt;email&gt;pontorez@pontorez.ru&lt;/email&gt;
      &lt;email&gt;webmaster@pontorez.ru&lt;/email&gt;
    &lt;/creator&gt;
    &lt;affiliation id="CD004002-aff-0001" countryCode="GB"&gt;
      &lt;orgName&gt;Example&lt;/orgName&gt;
      &lt;address&gt;
        &lt;street&gt;Finch Pavilion&lt;/street&gt;
        &lt;street&gt;Middle Way&lt;/street&gt;
        &lt;city&gt;Oxford&lt;/city&gt;
        &lt;country&gt;UK&lt;/country&gt;
        &lt;postCode&gt;OX9 7LG&lt;/postCode&gt;
      &lt;/address&gt;
    &lt;/affiliation&gt;
    &lt;affiliation id="CD004002-aff-0002" countryCode="GB"&gt;
      &lt;orgName&gt;Centre for Statistics in Software&lt;/orgName&gt;
      &lt;orgDiv&gt;Head of SEO Support&lt;/orgDiv&gt;
      &lt;address&gt;
        &lt;street&gt;Pearson College&lt;/street&gt;
        &lt;street&gt;Linton Road&lt;/street&gt;
        &lt;city&gt;Oxford&lt;/city&gt;
        &lt;country&gt;UK&lt;/country&gt;
        &lt;postCode&gt;OX9 6UD&lt;/postCode&gt;
      &lt;/address&gt;
    &lt;/affiliation&gt;
    &lt;affiliation id="CD004002-aff-0003" countryCode="DK"&gt;
      &lt;collabContact&gt;Monica Bond&lt;/collabContact&gt;
      &lt;orgName&gt;Creyts, Dept 7512&lt;/orgName&gt;
      &lt;orgDiv&gt;Nordic Hardware Centre&lt;/orgDiv&gt;
      &lt;address&gt;
        &lt;street&gt;Blegdamsvej 219&lt;/street&gt;
        &lt;city&gt;Copenhagen&lt;/city&gt;
        &lt;country&gt;Denmark&lt;/country&gt;
        &lt;postCode&gt;2900&lt;/postCode&gt;
      &lt;/address&gt;
    &lt;/affiliation&gt;
  &lt;/creatorGroup&gt;
  </code></pre>
  
  <p>XSL stylesheet that I created:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt;
    &lt;xsl:output method="xml" indent="yes"/&gt;
  
    &lt;xsl:key name="affiliations" match="ORGANISATION" use="."/&gt;
  
    &lt;xsl:template name="kreator"&gt;
      &lt;xsl:variable name="affid"&gt;
        &lt;!-- The numbering problem is in the below line: --&gt;
        &lt;xsl:number format="0001" value="position()"/&gt;
      &lt;/xsl:variable&gt;
  
      &lt;xsl:variable name="role"&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test="@ROLE='AUTHOR' or name()='GROUP'"&gt;author&lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;contact&lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/xsl:variable&gt;
  
      &lt;creator affil="CD004002-aff-{$affid}"&gt;
        &lt;xsl:if test="GROUP_NAME!=''"&gt;
          &lt;xsl:attribute name="type"&gt;collaboration&lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:attribute name="creatorRole"&gt;
          &lt;xsl:value-of select="$role"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:if test="$role='contact'"&gt;
          &lt;honorifics&gt;
            &lt;xsl:value-of select="PREFIX"/&gt;
          &lt;/honorifics&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="GROUP_NAME!=''"&gt;
          &lt;collab&gt;
            &lt;xsl:value-of select="GROUP_NAME"/&gt;
          &lt;/collab&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="FIRST_NAME"&gt;
          &lt;forenames&gt;
            &lt;xsl:value-of select="FIRST_NAME"/&gt;
          &lt;/forenames&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="MIDDLE_INITIALS!=''"&gt;
          &lt;surnamePrefix&gt;
            &lt;xsl:value-of select="MIDDLE_INITIALS"/&gt;
          &lt;/surnamePrefix&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="LAST_NAME"&gt;
          &lt;surname&gt;
            &lt;xsl:value-of select="LAST_NAME"/&gt;
          &lt;/surname&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="FOOTNOTE!='' and name()='PERSON'"&gt;
          &lt;note id="CD004002-note-{$affid}"&gt;
            &lt;p&gt;
              &lt;xsl:value-of select="FOOTNOTE"/&gt;
            &lt;/p&gt;
          &lt;/note&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="$role='contact'"&gt;
          &lt;jobTitle&gt;&lt;xsl:value-of select="POSITION"/&gt;&lt;/jobTitle&gt;
          &lt;email&gt;&lt;xsl:value-of select="EMAIL_1"/&gt;&lt;/email&gt;
          &lt;email&gt;&lt;xsl:value-of select="EMAIL_2"/&gt;&lt;/email&gt;
        &lt;/xsl:if&gt;
  
      &lt;/creator&gt;
      &lt;xsl:text&gt;&amp;#xA;&amp;#xA;&lt;/xsl:text&gt;
  
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="/CREATORS"&gt;
      &lt;xmp&gt;
        &lt;creatorGroup&gt;
          &lt;!-- list of creators: --&gt;
          &lt;xsl:for-each select="PERSON[@ROLE='AUTHOR'] | GROUP"&gt;
            &lt;xsl:call-template name="kreator"/&gt;
          &lt;/xsl:for-each&gt;
          &lt;xsl:for-each select="PERSON[@ROLE='CONTACT']"&gt;
            &lt;xsl:call-template name="kreator"/&gt;
          &lt;/xsl:for-each&gt;
          &lt;!-- list of affiliations: --&gt;
          &lt;xsl:for-each select="//ORGANISATION[generate-id(.)=generate-id(key('affiliations', .))]"&gt;
            &lt;affiliation&gt;
              &lt;xsl:attribute name="id"&gt;
                CD004002-aff-000&lt;xsl:value-of select="position()"/&gt;
              &lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="countryCode"&gt;
                &lt;xsl:value-of select="../COUNTRY/@CODE"/&gt;
              &lt;/xsl:attribute&gt;
              &lt;xsl:if test="../../CONTACT_PERSON"&gt;
                &lt;collabContact&gt;
                  &lt;xsl:value-of select="../../CONTACT_PERSON"/&gt;
                &lt;/collabContact&gt;
              &lt;/xsl:if&gt;
              &lt;orgName&gt;
                &lt;xsl:value-of select="."/&gt;
              &lt;/orgName&gt;
              &lt;xsl:if test="../DEPARTMENT!=''"&gt;
                &lt;orgDiv&gt;
                  &lt;xsl:value-of select="../DEPARTMENT"/&gt;
                &lt;/orgDiv&gt;
              &lt;/xsl:if&gt;
              &lt;address&gt;
                &lt;street&gt;
                  &lt;xsl:value-of select="../ADDRESS_1"/&gt;
                &lt;/street&gt;
                &lt;xsl:if test="../ADDRESS_2!=''"&gt;
                  &lt;street&gt;
                    &lt;xsl:value-of select="../ADDRESS_2"/&gt;
                  &lt;/street&gt;
                &lt;/xsl:if&gt;
  
                &lt;city&gt;
                  &lt;xsl:value-of select="../CITY"/&gt;
                &lt;/city&gt;
                &lt;country&gt;
                  &lt;xsl:value-of select="../COUNTRY"/&gt;
                &lt;/country&gt;
                &lt;postCode&gt;
                  &lt;xsl:value-of select="../ZIP"/&gt;
                &lt;/postCode&gt;
              &lt;/address&gt;
            &lt;/affiliation&gt;
            &lt;xsl:text&gt;&amp;#xA;&amp;#xA;&lt;/xsl:text&gt;
          &lt;/xsl:for-each&gt;
        &lt;/creatorGroup&gt;
      &lt;/xmp&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I.e. I want to get <code>&lt;creator&gt;</code> numbering like the below:</p>
  
  <pre><code>&lt;creator affil="CD004002-aff-0001" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0001" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0002" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0001" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0003" type="collaboration" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0003" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0001" creatorRole="contact"/&gt;
  </code></pre>
  
  <p>While my current XSL stylesheet produces wrong @affil's:</p>
  
  <pre><code>&lt;creator affil="CD004002-aff-0004" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0004" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0001" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0004" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0002" type="collaboration" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0002" creatorRole="author"/&gt;
  &lt;creator affil="CD004002-aff-0004" creatorRole="contact"/&gt;
  </code></pre>
  
  <p>Can you help please? Thanks.</p>