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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:12:44+00:00 2026-05-24T22:12:44+00:00

I’m using XSLT to transform from one format of XML into another but I

  • 0

I’m using XSLT to transform from one format of XML into another but I also need to do some value substitutions at the same time if possible. Can someone provide a solution to change a large number of values; e.g. “AppName” should be changed to “1”, “AppNameTwo” to “2” and I’d ideally like to do this via some type of look-up lists within the XSLT:

<Application>
 <oldvalue="AppName" replacewith="1">
 <oldvalue="AppNameTwo" replacewith="2">
</Application>
<ResponseOne>
 <oldvalue="True" replacewith="Okay">
 <oldvalue="False" replacewith="Error">
</ResponseOne>

The only way I can currently think of doing this is instead via a number of many nested replaces?

Input

<Message>
  <Header>
    <Application>AppName</Application>
    <ResponseOne>True</ResponseOne>
    ...
</Header>
</Message>

XSLT so far

    <?xml version="1.0" encoding="utf-8"?>
        <xsl:stylesheet version="1.0">
        <xsl:template match="/">
        <n1:Message>
          <Header>
            <Application><xsl:value-of select="//Message/Organisation/Application/Name"/>   </Application>
   <Response><xsl:value-of select="//Message/Organisation/Application/ResponseOne"/>   </Response>
            ...
          </Header>
    </n1:Message>

Required Output

 <?xml version="1.0" encoding="utf-8"?>
        <n1:Message>
          <Header>
          <Application>1</Application>
          <Response>Error</Response>
            ...
          </Header>
    </n1:Message>

Intending to run this XSLT within Visual Studio 2010.

  • 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-24T22:12:46+00:00Added an answer on May 24, 2026 at 10:12 pm

    This simple transformation (only a single template overriding the identity rule and no need for extension functions), allows the use of huge number of replacement rules, without the need to change the code at all. Another alternative is to specify the value of the global parameter $pReps outside of the transformation — then this code can be even slightly simplified:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pReps">
      <elem name="Application">
       <replace>
         <this>AppName</this>
         <with>1</with>
       </replace>
       <replace>
         <this>AppNameTwo</this>
         <with>2</with>
       </replace>
      </elem>
      <elem name="ResponseOne">
       <replace>
         <this>True</this>
         <with>Okay</with>
       </replace>
       <replace>
         <this>False</this>
         <with>Error</with>
       </replace>
      </elem>
     </xsl:param>
    
     <xsl:variable name="vReps" select=
     "document('')/*/xsl:param[@name='pReps']"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text()">
      <xsl:variable name="vNewVal" select=
       "$vReps/elem
           [@name=name(current()/..)]
                  /replace[this = current()]
                     /with/text()
       "/>
    
       <xsl:copy-of select=
        "$vNewVal | self::text()[not($vNewVal)]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When applied on the provided XML document:

    <Message>
      <Header>
        <Application>AppName</Application>
        <ResponseOne>True</ResponseOne>
        ...
    </Header>
    </Message>
    

    the wanted, correct result is produced:

    <Message>
       <Header>
          <Application>1</Application>
          <ResponseOne>Okay</ResponseOne>
        ...
    </Header>
    </Message>
    

    Explanation:

    1. The identity rule (template) copies every node “as-is”.

    2. The replacement rules are coded as a sequence of elem elements that are children of the global paramerte pReps. The structure and meaning of every elem element should be self-explanatory.

    3. There is a single template overriding the identity rule, that matches any text node. Within this template a possible new value is calculated as defined by the variable $vNewVal. This is either the empty node-set (in case the parent name of the current node and the string value of the current node are not matced by any replace/this value from the $pReps. Or, if matched, this is the with sibling of the matching replace/this value from the $pReps. Finally, either $vNewVal (if not empty) or the current node are copied.

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
I need to clean up various Word 'smart' characters in user input, including but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.