Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:08:08+00:00 2026-05-12T01:08:08+00:00

I’m new in xml, sorry for the dumb question. I’m trying to create xsl

  • 0

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 <creator>‘s correctly (creator@affil in Destination xml).

Source:

<?xml version="1.0" encoding="iso-8859-1"?>
<CREATORS>
  <PERSON ROLE="CONTACT">
    <PREFIX>Prof</PREFIX>
    <FIRST_NAME>Mike</FIRST_NAME>
    <MIDDLE_INITIALS>J</MIDDLE_INITIALS>
    <LAST_NAME>Petrov</LAST_NAME>
    <SUFFIX/>
    <POSITION>Director</POSITION>
    <EMAIL_1>pontorez@pontorez.ru</EMAIL_1>
    <EMAIL_2>webmaster@pontorez.ru</EMAIL_2>
    <URL>www.pontorez.ru</URL>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT/>
      <ORGANISATION>Example</ORGANISATION>
      <ADDRESS_1>Finch Pavilion</ADDRESS_1>
      <ADDRESS_2>Middle Way</ADDRESS_2>
      <CITY>Oxford</CITY>
      <ZIP>OX9 7LG</ZIP>
      <REGION/>
      <COUNTRY CODE="GB">UK</COUNTRY>
      <PHONE_1>+380 6245 716300</PHONE_1>
      <PHONE_2/>
      <FAX_1>+380 6245 716311</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE/>
  </PERSON>
  <PERSON ID="7091" ROLE="AUTHOR">
    <PREFIX>Prof</PREFIX>
    <FIRST_NAME>Mike</FIRST_NAME>
    <MIDDLE_INITIALS>J</MIDDLE_INITIALS>
    <LAST_NAME>Petrov</LAST_NAME>
    <SUFFIX/>
    <POSITION>Director</POSITION>
    <EMAIL_1>pontorez@pontorez.ru</EMAIL_1>
    <EMAIL_2>webmaster@pontorez.ru</EMAIL_2>
    <URL>www.pontorez.ru</URL>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT/>
      <ORGANISATION>Example</ORGANISATION>
      <ADDRESS_1>Finch Pavilion</ADDRESS_1>
      <ADDRESS_2>Middle Way</ADDRESS_2>
      <CITY>Oxford</CITY>
      <ZIP>OX9 7LG</ZIP>
      <REGION/>
      <COUNTRY CODE="GB">UK</COUNTRY>
      <PHONE_1>+380 6245 716300</PHONE_1>
      <PHONE_2/>
      <FAX_1>+380 6245 716311</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE>Author footnote</FOOTNOTE>
  </PERSON>
  <PERSON ID="7094" ROLE="AUTHOR">
    <PREFIX>Mrs</PREFIX>
    <FIRST_NAME>Anne</FIRST_NAME>
    <MIDDLE_INITIALS/>
    <LAST_NAME>Spencer</LAST_NAME>
    <SUFFIX/>
    <POSITION/>
    <EMAIL_1>aspencer@Hardware.co.uk</EMAIL_1>
    <EMAIL_2/>
    <URL/>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT/>
      <ORGANISATION>Example</ORGANISATION>
      <ADDRESS_1>SEO R&amp;D Programme</ADDRESS_1>
      <ADDRESS_2>Finch Pavilion, Middle Way</ADDRESS_2>
      <CITY>Oxford</CITY>
      <ZIP>OX9 7LG</ZIP>
      <REGION>Oxfordshire</REGION>
      <COUNTRY CODE="GB">UK</COUNTRY>
      <PHONE_1>+380 6245 716300</PHONE_1>
      <PHONE_2/>
      <FAX_1>+380 6245 716311</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE/>
  </PERSON>
  <PERSON ID="15756" ROLE="AUTHOR">
    <PREFIX>Mr</PREFIX>
    <FIRST_NAME>Ed</FIRST_NAME>
    <MIDDLE_INITIALS/>
    <LAST_NAME>Gantos</LAST_NAME>
    <SUFFIX/>
    <POSITION>Senior Medical Statistician</POSITION>
    <EMAIL_1>santos@xxx.org.uk</EMAIL_1>
    <EMAIL_2/>
    <URL>http://www.isds.sxo.ac.uk/</URL>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT>Head of SEO Support</DEPARTMENT>
      <ORGANISATION>Centre for Statistics in Software</ORGANISATION>
      <ADDRESS_1>Pearson College</ADDRESS_1>
      <ADDRESS_2>Linton Road</ADDRESS_2>
      <CITY>Oxford</CITY>
      <ZIP>OX9 6UD</ZIP>
      <REGION/>
      <COUNTRY CODE="GB">UK</COUNTRY>
      <PHONE_1>+380 6245 112404</PHONE_1>
      <PHONE_2/>
      <FAX_1>+380 6245 112424</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE/>
  </PERSON>
  <PERSON ID="7092" ROLE="AUTHOR">
    <PREFIX>Dr</PREFIX>
    <FIRST_NAME>Sherry</FIRST_NAME>
    <MIDDLE_INITIALS/>
    <LAST_NAME>Wilson</LAST_NAME>
    <SUFFIX/>
    <POSITION/>
    <EMAIL_1>wilson@Hardware.co.uk</EMAIL_1>
    <EMAIL_2/>
    <URL/>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT/>
      <ORGANISATION>Example</ORGANISATION>
      <ADDRESS_1>SEO R&amp;D Programme</ADDRESS_1>
      <ADDRESS_2>Finch Pavilion, Middle Way</ADDRESS_2>
      <CITY>Oxford</CITY>
      <ZIP>OX9 7LG</ZIP>
      <REGION>Oxfordshire</REGION>
      <COUNTRY CODE="GB">UK</COUNTRY>
      <PHONE_1>+380 6245 716300</PHONE_1>
      <PHONE_2/>
      <FAX_1>+380 6245 716311</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE/>
  </PERSON>
  <GROUP ID="????">
    <GROUP_NAME>Bond team</GROUP_NAME>
    <CONTACT_PERSON>Monica Bond</CONTACT_PERSON>
    <EMAIL_1>mk@Hardware.dk</EMAIL_1>
    <URL/>
    <ADDRESS>
      <DEPARTMENT>Nordic Hardware Centre</DEPARTMENT>
      <ORGANISATION>Creyts, Dept 7512</ORGANISATION>
      <ADDRESS_1>Blegdamsvej 219</ADDRESS_1>
      <ADDRESS_2/>
      <CITY>Copenhagen</CITY>
      <ZIP>2900</ZIP>
      <REGION/>
      <COUNTRY CODE="DK">Denmark</COUNTRY>
      <PHONE_1>+415 7667 7110</PHONE_1>
      <PHONE_2>+415 1234 9429</PHONE_2>
      <FAX_1>+415 7667 7007</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE>Group footnote</FOOTNOTE>
  </GROUP>
  <PERSON ID="3" ROLE="AUTHOR">
    <PREFIX>Ms</PREFIX>
    <FIRST_NAME>Monica</FIRST_NAME>
    <MIDDLE_INITIALS/>
    <LAST_NAME>Bond</LAST_NAME>
    <SUFFIX/>
    <POSITION>Director of the Hardware Information Management System</POSITION>
    <EMAIL_1>mk@Hardware.dk</EMAIL_1>
    <EMAIL_2/>
    <URL>www.cc-ims.net</URL>
    <MOBILE_PHONE/>
    <ADDRESS>
      <DEPARTMENT>Nordic Hardware Centre</DEPARTMENT>
      <ORGANISATION>Creyts, Dept 7512</ORGANISATION>
      <ADDRESS_1>Blegdamsvej 219</ADDRESS_1>
      <ADDRESS_2/>
      <CITY>Copenhagen</CITY>
      <ZIP>2900</ZIP>
      <REGION/>
      <COUNTRY CODE="DK">Denmark</COUNTRY>
      <PHONE_1>+415 7667 7110</PHONE_1>
      <PHONE_2>+415 1234 9429</PHONE_2>
      <FAX_1>+415 7667 7007</FAX_1>
      <FAX_2/>
    </ADDRESS>
    <FOOTNOTE/>
  </PERSON>
</CREATORS>

Destination:

<?xml version="1.0" encoding="utf-8"?>
<creatorGroup>
  <creator affil="CD004002-aff-0001" creatorRole="author">
    <forenames>Mike</forenames>
    <surnamePrefix>J</surnamePrefix>
    <surname>Petrov</surname>
    <note id="CD004002-note-0001">
      <p>Author footnote</p>
    </note>
  </creator>
  <creator affil="CD004002-aff-0001" creatorRole="author">
    <forenames>Anne</forenames>
    <surname>Spencer</surname>
  </creator>
  <creator affil="CD004002-aff-0002" creatorRole="author">
    <forenames>Ed</forenames>
    <surname>Gantos</surname>
  </creator>
  <creator affil="CD004002-aff-0001" creatorRole="author">
    <forenames>Sherry</forenames>
    <surname>Wilson</surname>
  </creator>
  <creator affil="CD004002-aff-0003" type="collaboration" creatorRole="author">
    <collab>Bond team</collab>
  </creator>
  <creator affil="CD004002-aff-0003" creatorRole="author">
    <forenames>Monica</forenames>
    <surname>Bond</surname>
  </creator>
  <creator affil="CD004002-aff-0001" creatorRole="contact">
    <honorifics>Prof</honorifics>
    <forenames>Mike</forenames>
    <surnamePrefix>J</surnamePrefix>
    <surname>Petrov</surname>
    <jobTitle>Director</jobTitle>
    <email>pontorez@pontorez.ru</email>
    <email>webmaster@pontorez.ru</email>
  </creator>
  <affiliation id="CD004002-aff-0001" countryCode="GB">
    <orgName>Example</orgName>
    <address>
      <street>Finch Pavilion</street>
      <street>Middle Way</street>
      <city>Oxford</city>
      <country>UK</country>
      <postCode>OX9 7LG</postCode>
    </address>
  </affiliation>
  <affiliation id="CD004002-aff-0002" countryCode="GB">
    <orgName>Centre for Statistics in Software</orgName>
    <orgDiv>Head of SEO Support</orgDiv>
    <address>
      <street>Pearson College</street>
      <street>Linton Road</street>
      <city>Oxford</city>
      <country>UK</country>
      <postCode>OX9 6UD</postCode>
    </address>
  </affiliation>
  <affiliation id="CD004002-aff-0003" countryCode="DK">
    <collabContact>Monica Bond</collabContact>
    <orgName>Creyts, Dept 7512</orgName>
    <orgDiv>Nordic Hardware Centre</orgDiv>
    <address>
      <street>Blegdamsvej 219</street>
      <city>Copenhagen</city>
      <country>Denmark</country>
      <postCode>2900</postCode>
    </address>
  </affiliation>
</creatorGroup>

XSL stylesheet that I created:

<?xml version="1.0" encoding="utf-8"?>
<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">
  <xsl:output method="xml" indent="yes"/>

  <xsl:key name="affiliations" match="ORGANISATION" use="."/>

  <xsl:template name="kreator">
    <xsl:variable name="affid">
      <!-- The numbering problem is in the below line: -->
      <xsl:number format="0001" value="position()"/>
    </xsl:variable>

    <xsl:variable name="role">
      <xsl:choose>
        <xsl:when test="@ROLE='AUTHOR' or name()='GROUP'">author</xsl:when>
        <xsl:otherwise>contact</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <creator affil="CD004002-aff-{$affid}">
      <xsl:if test="GROUP_NAME!=''">
        <xsl:attribute name="type">collaboration</xsl:attribute>
      </xsl:if>
      <xsl:attribute name="creatorRole">
        <xsl:value-of select="$role"/>
      </xsl:attribute>
      <xsl:if test="$role='contact'">
        <honorifics>
          <xsl:value-of select="PREFIX"/>
        </honorifics>
      </xsl:if>
      <xsl:if test="GROUP_NAME!=''">
        <collab>
          <xsl:value-of select="GROUP_NAME"/>
        </collab>
      </xsl:if>
      <xsl:if test="FIRST_NAME">
        <forenames>
          <xsl:value-of select="FIRST_NAME"/>
        </forenames>
      </xsl:if>
      <xsl:if test="MIDDLE_INITIALS!=''">
        <surnamePrefix>
          <xsl:value-of select="MIDDLE_INITIALS"/>
        </surnamePrefix>
      </xsl:if>
      <xsl:if test="LAST_NAME">
        <surname>
          <xsl:value-of select="LAST_NAME"/>
        </surname>
      </xsl:if>
      <xsl:if test="FOOTNOTE!='' and name()='PERSON'">
        <note id="CD004002-note-{$affid}">
          <p>
            <xsl:value-of select="FOOTNOTE"/>
          </p>
        </note>
      </xsl:if>
      <xsl:if test="$role='contact'">
        <jobTitle><xsl:value-of select="POSITION"/></jobTitle>
        <email><xsl:value-of select="EMAIL_1"/></email>
        <email><xsl:value-of select="EMAIL_2"/></email>
      </xsl:if>

    </creator>
    <xsl:text>&#xA;&#xA;</xsl:text>

  </xsl:template>

  <xsl:template match="/CREATORS">
    <xmp>
      <creatorGroup>
        <!-- list of creators: -->
        <xsl:for-each select="PERSON[@ROLE='AUTHOR'] | GROUP">
          <xsl:call-template name="kreator"/>
        </xsl:for-each>
        <xsl:for-each select="PERSON[@ROLE='CONTACT']">
          <xsl:call-template name="kreator"/>
        </xsl:for-each>
        <!-- list of affiliations: -->
        <xsl:for-each select="//ORGANISATION[generate-id(.)=generate-id(key('affiliations', .))]">
          <affiliation>
            <xsl:attribute name="id">
              CD004002-aff-000<xsl:value-of select="position()"/>
            </xsl:attribute>
            <xsl:attribute name="countryCode">
              <xsl:value-of select="../COUNTRY/@CODE"/>
            </xsl:attribute>
            <xsl:if test="../../CONTACT_PERSON">
              <collabContact>
                <xsl:value-of select="../../CONTACT_PERSON"/>
              </collabContact>
            </xsl:if>
            <orgName>
              <xsl:value-of select="."/>
            </orgName>
            <xsl:if test="../DEPARTMENT!=''">
              <orgDiv>
                <xsl:value-of select="../DEPARTMENT"/>
              </orgDiv>
            </xsl:if>
            <address>
              <street>
                <xsl:value-of select="../ADDRESS_1"/>
              </street>
              <xsl:if test="../ADDRESS_2!=''">
                <street>
                  <xsl:value-of select="../ADDRESS_2"/>
                </street>
              </xsl:if>

              <city>
                <xsl:value-of select="../CITY"/>
              </city>
              <country>
                <xsl:value-of select="../COUNTRY"/>
              </country>
              <postCode>
                <xsl:value-of select="../ZIP"/>
              </postCode>
            </address>
          </affiliation>
          <xsl:text>&#xA;&#xA;</xsl:text>
        </xsl:for-each>
      </creatorGroup>
    </xmp>
  </xsl:template>

</xsl:stylesheet>

I.e. I want to get <creator> numbering like the below:

<creator affil="CD004002-aff-0001" creatorRole="author"/>
<creator affil="CD004002-aff-0001" creatorRole="author"/>
<creator affil="CD004002-aff-0002" creatorRole="author"/>
<creator affil="CD004002-aff-0001" creatorRole="author"/>
<creator affil="CD004002-aff-0003" type="collaboration" creatorRole="author"/>
<creator affil="CD004002-aff-0003" creatorRole="author"/>
<creator affil="CD004002-aff-0001" creatorRole="contact"/>

While my current XSL stylesheet produces wrong @affil’s:

<creator affil="CD004002-aff-0004" creatorRole="author"/>
<creator affil="CD004002-aff-0004" creatorRole="author"/>
<creator affil="CD004002-aff-0001" creatorRole="author"/>
<creator affil="CD004002-aff-0004" creatorRole="author"/>
<creator affil="CD004002-aff-0002" type="collaboration" creatorRole="author"/>
<creator affil="CD004002-aff-0002" creatorRole="author"/>
<creator affil="CD004002-aff-0004" creatorRole="contact"/>

Can you help please? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:08:08+00:00Added an answer on May 12, 2026 at 1:08 am

    Your problem is that when you do:

    <xsl:call-template name="kreator" />
    

    then you do it in the context of the <PERSON> or <GROUP> you are currently handling.

    This means that position() will tell you the position of those elements. It cannot magically know that you are interested in the position of the first <ORGANISATION> that matches the current one.

    And this means you must iterate all <ORGANISATION>s much the same way you do it to calculate the <affiliation> attribute @id:

    <xsl:variable name="affid">
      <xsl:variable name="org" select="ADDRESS/ORGANISATION" />
      <xsl:for-each select="//ORGANISATION[
        generate-id()
        =
        generate-id(key('affiliations', .)[1])
      ]">
        <xsl:if test=". = $org">
          <xsl:number format="0001" value="position()"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>
    

    Note the use of <xsl:if> to make sure that the variable eventually contains only one value, even though you are looking through all of them.

    For larger documents, you could introduce another key:

    <xsl:key name="organisations" match="ORGANISATION" use="'all'" />
    

    and use that as a drop-in replacement for all the comparatively inefficient “//ORGANISATION” expressions, e.g. instead of:

    <xsl:for-each select="//ORGANISATION">
      <!-- ... -->
    </xsl:for-each>
    

    use:

    <xsl:for-each select="key('organisations', 'all')">
      <!-- ... -->
    </xsl:for-each>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an XML file, the creators of it stuck in a bunch social
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.