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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:41:01+00:00 2026-06-10T16:41:01+00:00

I have a little problem. A node in my XML may contains and integer,

  • 0

I have a little problem.
A node in my XML may contains and integer, and i have to replace this integer by a string.
Each number match with a string.

For example i have:


Integer – String

1 – TODO

2 – IN PROGRESS

3 – DONE

4 – ERROR

5 – ABORTED


Original XML:

    <root>
       <status>1</status>
    </root>

Converted XML:

    <root>
       <status>TODO</status>
    </root>

So i want replace 1 by “TODO”, 2 by “IN PROGRESS” …

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:template match="/root/status">
    <root>
      <status>
                <xsl:variable name="text" select="." />

                <xsl:choose>
                    <xsl:when test="contains($text, '1')">

                        <xsl:value-of select="'TODO'"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$text"/>
                    </xsl:otherwise>
                </xsl:choose>
    </status></root>
            </xsl:template>
    </xsl:stylesheet>

I’am asking if there is another way to do that.

  • 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-10T16:41:02+00:00Added an answer on June 10, 2026 at 4:41 pm

    There are a number of ways of doing this. Where the translation is from consecutive integers in the range 1 to N, I would use

    <xsl:variable name="index" select="xs:integer(status)"/>
    <xsl:value-of select="('TODO', 'IN PROGRESS', 'DONE', 'ERROR', 'ABORTED')[$index]"/>
    

    In other cases where there’s a small number of values I might use template rules:

    <xsl:template match="status[.='1']" mode="lookup">TODO</xsl:template>
    <xsl:template match="status[.='2']" mode="lookup">IN PROGRESS</xsl:template>
    

    etc.

    In other cases a lookup table makes sense (note that Dimitre’s version with its cumbersome document(”) call is designed for XSLT 1.0 – it’s considerably simpler if you’re using 2.0. When people don’t say what version they are using I generally assume 2.0 and Dimitre generally assumes 1.0.)

    I’m increasingly seeing people make the mistake of using contains() when they mean “=”. If you want to test whether the content of a node is “X”, use $node = "X", not contains($node, "X").

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

Sidebar

Related Questions

I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
I have a little problem. I have some dynamically created tables and each row
Hey most of my issue has been solved but i have little problem This
i have little problem with if { string nom; string ou; nom = 1;
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have little unusual problem to solve. I need some hint or links to
I have a little problem about the sort direction of a specific column in
I have a little problem with Jquery getJSON function. my json here { entries:

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.