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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:41:38+00:00 2026-05-28T06:41:38+00:00

I have a XML file similar to the following: <a> <b value=a123 /> <b

  • 0

I have a XML file similar to the following:

<a>
  <b value="a123" />
  <b value="b234" />
  <b value="c345" />
</a>

I need to map the attributes to some other value. For example, I want to replace a123 with q999, b234 with z998 and c345 with u997. Is it possible to do such transformation efficiently using XSLT? The mapping itself is generated, so I can convert it into almost any format. For now, let’s say it’s the following XML file:

<map>
  <item from="c345" to="u997" />
  <item from="b234" to="z998" />
  <item from="a123" to="q999" />
</map>

Maybe there’s a better tool than XSLT to do such transformation? Currently I just sed through the file many times. Obviously this solution is horribly inefficient and doesn’t scale at all.

  • 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-28T06:41:39+00:00Added an answer on May 28, 2026 at 6:41 am

    As easy as this:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <my:map>
       <map>
        <item from="c345" to="u997" />
        <item from="b234" to="z998" />
        <item from="a123" to="q999" />
       </map>
     </my:map>
    
     <xsl:variable name="vMap" select=
      "document('')/*/my:map/*/*"/>
    
     <xsl:template match="node()|@*">
       <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
     "@value[. = document('')/*/my:map/*/*/@from]">
      <xsl:attribute name="value">
       <xsl:value-of select="$vMap[@from = current()]/@to"/>
      </xsl:attribute>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <a>
        <b value="a123" />
        <b value="b234" />
        <b value="c345" />
    </a>
    

    the wanted, correct result is produced:

    <a>
       <b value="q999"/>
       <b value="z998"/>
       <b value="u997"/>
    </a>
    

    Explanation:

    1. Overriding the identity template for value attributes whos value is equal to a from attribute in the map.

    2. The map is presented inline in the transformation and accessed using the document() function. Alternatively, the filepath to the file containing the map can be passed as external parameter to the transformation and the Map XML document can be accessed using again the document() function, passing as argument to it this filepath.

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

Sidebar

Related Questions

I have an XML file with a lot of nodes similar to the following
I have an XML file similar to the following: <novel> <paragraphs> <paragraph> <choice>This is
I have an XML file similar in structure to the following: <Parent> <Child>5</Child> <Child>3</Child>
I have the following XML file that I need to convert to JSON in
I have an XML file content similar to the following: <?xml version=1.0 encoding=utf-8?> <Content>
Let's say I have the following XML file <a id=123> <b type=foo value=1 />
I have an XML file from which I am parsing some content to display
I have a xml file which I need to open with Microsoft Word 2007.
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have an xml file with the following structure: <main_tag> <first> <tag1>val1</tag1> <conf> <tag2>val2</tag2>

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.