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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:47:58+00:00 2026-06-09T04:47:58+00:00

I have the following elements in my xmi file: <element1 id= 3 > <element2

  • 0

I have the following elements in my xmi file:

<element1 id= 3 >

<element2 id= 3>

I want to transform them into something like:

<element1 id= 3 name =element2>
<element2 id= 3>

I am using xslt to transform:

<xsl:if test="@id = //*[@id]/@id">
                <xsl:sequence
                    select="fn:createAtt('name',X)" />
            </xsl:if>

I want to compare the id of two elements and in case they match then i want to save the name of second element (element2) into the name attribute of first element.

The comparison works ok. The problem is how to read the name of the second element ? I tried to use the name() function but am not able to read exactly that name that matches the comparison.

  • 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-06-09T04:48:02+00:00Added an answer on June 9, 2026 at 4:48 am

    I would do it like this: first define a key as

    <xsl:key name="el-by-id" match="*" use="@id"/>
    

    then I would write a template

    <xsl:template match="*[@id]">
      <xsl:variable name="same-id" use="key('el-by-id', @id) except ."/>
      <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:if test="$same-id">
           <xsl:attribute name="name" select="node-name($same-id[1])"/>
         </xsl:if>
         <xsl:apply-templates/>
      </xsl:copy>
    </xsl:template>
    

    That way you can efficiently reference the elements using a key, then if one element of the same id is found the attribute named name is created. I used the XSLT/XPath 2.0 node-name function, depending on your exact requirements you might want to use <xsl:attribute name="name" select="name($same-id[1])"/> instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following question. I'd like to place a file named data.xml into sdcard/appname
If I have the following DOM elements <div class=item>content1</div> <div class=item>content2</div> how, using jQuery
I have following HTML with two elements having the same name <input type=hidden name=
In my ASP.NET's Web Config file I have the following location elements defined: <location
I have an XML file with the following elements and attributes: <element> <unit id=1
I have the following elements (excuse the syntax) :- <xs:complexType name=shop_T> <xs:element name=city type=xs:string
I have the following elements in a HTML page: <body> <div style=height:100%; width:100%> <div
I have the following Table elements how do i run a query that reproduce
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a window with the following elements, and I'm trying to access the

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.