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 3333264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:46:39+00:00 2026-05-17T23:46:39+00:00

Lets say you have an xml document like <parents> <parent> <element /> <element />

  • 0

Lets say you have an xml document like

<parents>
    <parent>
        <element />
        <element />
    </parent>
    <parent>
        <element />
        <element />
    </parent>
</parents>

While processing I need to know that the elements are 1, 2, 3, 4 in the document, not that but calling position() will return 1, 2, 1, 2. Normally I would modify the xml, but, in this case, it is not possible, while I am processing parent 2, I somehow need to know that it’s first element, is really element 3.

Thanks,
-c

  • 1 1 Answer
  • 3 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-17T23:46:39+00:00Added an answer on May 17, 2026 at 11:46 pm

    Use <xsl:number>

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="element">
         <xsl:copy>
           <xsl:number level="any" count="element"/>
         </xsl:copy>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <parents>
        <parent>
            <element />
            <element />
        </parent>
        <parent>
            <element />
            <element />
        </parent>
    </parents>
    

    produces the wanted result:

    <parents>
        <parent>
            <element>1</element>
            <element>2</element>
        </parent>
        <parent>
            <element>3</element>
            <element>4</element>
        </parent>
    </parents>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a xslt stylesheet like the following: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
Let's say that I have something like this in my web.xml file. <filter name=foo>
So i have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <gesmes:Envelope
Let's say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword>
Lets say you have an XML like like this: <data> <messages> <message name=Person id=P>
Lets say I have the following XML document: <response> <businessEntity> <ABN> <identifierValue></identifierValue> <isCurrentIndicator></isCurrentIndicator> <replacedIdentifierValue
Just as an example, lets say I have a customerX.xml file that I've unmarshalled
Lets say I have a schema that defines the following XML: <Values> <Add Key=Key1>Value
Ok. I have an attribute in an xml document that I know will occur
Let's say I have an xml document like this: <director> <play> <t>Nutcracker</t> <a>Tom Cruise</a>

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.