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

  • SEARCH
  • Home
  • 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 7698531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:15:50+00:00 2026-05-31T22:15:50+00:00

My XML document looks like this- <doc> <system_data> <registry_item id=1> <hive>HKEY_LOCAL_MACHINE</hive> </registry_item> <file_item id=2>

  • 0

My XML document looks like this-

<doc>

  <system_data>
    <registry_item id="1">
      <hive>HKEY_LOCAL_MACHINE</hive>
    </registry_item>
    <file_item id="2">
      <filepath>C:\Windows\System32\msasn1.dll</filepath>    
    </file_item>
  </system_data>

</doc>

I would like to transform it such as “id” attribute value is incremented sequentially e.g :

<doc>

  <system_data>
    <registry_item id="10">
      <hive>HKEY_LOCAL_MACHINE</hive>
    </registry_item>
    <file_item id="11">
      <filepath>C:\Windows\System32\msasn1.dll</filepath>    
    </file_item>
  </system_data>

</doc>

I am using the “identity” design and my xsl looks like this-

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:xslt="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="Identity.xsl"/>
<xslt:param name="newID" />
  <xsl:template match="//system_data/*">
      <xsl:for-each select="@id">
        <xsl:attribute name="id">
            <xsl:value-of select="number($newID)+1"/>      
        </xsl:attribute>
      </xsl:for-each>   
  </xsl:template> 
</xsl:stylesheet>

I am passing newID value as “10”. How to I select each attribute and increment its value?

Indentity.xsl looks like this-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Whenever you match any node or any attribute -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

When I apply xsl, I am getting following error-

An attribute node (id) cannot be created after the children of the containing element
  • 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-31T22:15:51+00:00Added an answer on May 31, 2026 at 10:15 pm

    Try changing your template for match="//system_data/*" to this:

      <xsl:template match="@id">
        <xsl:attribute name="id">
          <xsl:value-of select="number($newID)+count(preceding::*/@id)"/>
        </xsl:attribute>
      </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My XML document looks like this When I run XPATH query //collected_objects , I
I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley
I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
I'm using nokogiri with an xml document that looks something like this: <songs> <song>
So I have a xml document loaded in JavaScript variable. Xml looks like this:
My XML looks like this. I would like to export collected_objects into another document.
I have a XML org.w3c.dom.Document object. It looks sorta like this: <A> <B> <C/>
I have an XML document that looks like this: <Data xmlns=http://www.domain.com/schema/data xmlns:dmd=http://www.domain.com/schema/data-metadata > <Something>...</Something>
Say I have a xml document that looks like this <foo> <bar id=9 />

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.