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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:53:05+00:00 2026-06-08T00:53:05+00:00

Lets say I have the following xml. <root> <data> <a>ATTITUDE_ANNOYED</a> <b>ATTITUDE_CAUTIOUS</b> <c>25</c> <d>30</d> </data>

  • 0

Lets say I have the following xml.

<root>
  <data>
    <a>ATTITUDE_ANNOYED</a>
    <b>ATTITUDE_CAUTIOUS</b>
    <c>25</c>
    <d>30</d>
  </data>
</root>

Ignoring the schema of my output, I want my output to present A as “Cautious” (one level up from annoyed), B as ”
Pleased” (one level up from Cautious”) and I want to perform some maths on C and D to convert the value into something slightly different.

I’ve had a look at a bunch of similar questions here (and I’m new to XSLT so maybe I don’t quite get it) but a lot of the solutions appear to be “in-line”, i.e. you modify the result as you transform it. This is okay but in my real example there are a lot of these values and I don’t want to be performing the exact same conversion in multiple places (DRY). I just want to more or less pre-process the entire document and convert a bunch of values into other values (using just a few formulas) before I start the transformation.

What would be the best way to achieve this? I’m not particularly interested in performance so is there a way that I can run a prior transformation to easily transform specific values without modifying the structure?

UPDATE: (DevNull asked for my output desires) The output isn’t exactly finalised. I’m trying to help a group at CivFanatics produce a guide on the differences between the AIs whose values derive from an xml file. There are a ton of leaders and a ton of values that need converting, by hand its taking them 2 hours per leader at the moment and the final formatting hasn’t been decided on so I thought we’d all save time by using something like XLST.

Here is a rough example of a demo I’m working on.

<xsl:template match="data"> 
  <h3>Attitude Thresholds</h3>
  <table border="1">
    <tr><td>Will open borders</td><td><xsl:value-of select="a"/></td></tr>
    <tr><td>Will trade techs</td><td><xsl:value-of select="b"/></td></tr>
  </table>
</xsl:template>

To clarify A and B are OpenBordersRefuseAttitudeThreshold and TechRefuseAttitudeThreshold. The guide is more readable if these are WillOpenBordersAt and WillTradeTechAt as opposed to the original values in the xml file so I need to nudge them up a value for the final output.

There are additional conversions that have been discussed:

iWonderConstructRand -> Builds Wonders

0 -> 0/10
5 -> 1/10
10 -> 2/10
15 -> 3/10
20 -> 4/10
25 -> 5/10
30 -> 6/10
35 -> 7/10
40 -> 8/10
45 -> 9/10
50 -> 10/10

So that’s values such as C or D. They range between 0-50 and should be put into a 0-10 format for readability. There are a fair few of these values too.

Also there are conversions like “GoodieBaddie” which vary from 0 to 10. Which we wish to convert to something like:

0-3  -> Bad(x)
4-6  -> Neutral(x)
7-10 -> Good(x)

Where (x) is the original value.
Am I even using the right tool for the job here or is it borderline? I figured XLST would be a good choice to enable other contributors to not have to rely on the devs to make changes to the formatting/layout (as xlst is easier to edit then say C# or Python).

  • 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-08T00:53:07+00:00Added an answer on June 8, 2026 at 12:53 am

    This transformation:

    <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:attitudes>
       <a val="1">ANNOYED</a>
       <a val="2">CAUTIOUS</a>
       <a val="3">PLEASED</a>
     </my:attitudes>
    
     <xsl:variable name="vAttitudes" select="document('')/*/my:attitudes/*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="*[starts-with(., 'ATTITUDE_')]/text()">
      <xsl:variable name="vVal" select=
      "$vAttitudes[. = substring-after(current(), '_')]/@val"/>
    
      <xsl:value-of select="concat('ATTITUDE_', $vAttitudes[@val = $vVal+1])"/>
     </xsl:template>
    
     <xsl:template match="*[floor(.) = .]/text()">
      <xsl:value-of select="concat(round(. div 5), '/10')"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <root>
        <data>
            <a>ATTITUDE_ANNOYED</a>
            <b>ATTITUDE_CAUTIOUS</b>
            <c>25</c>
            <d>30</d>
        </data>
    </root>
    

    produces the wanted, correct result:

    <root>
       <data>
          <a>ATTITUDE_CAUTIOUS</a>
          <b>ATTITUDE_PLEASED</b>
          <c>5/10</c>
          <d>6/10</d>
       </data>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a schema that defines the following XML: <Values> <Add Key=Key1>Value
Lets say we have the following XML: <root> <sub> <id>1</id> <values> <value>1</value> <value>2</value> </values>
Lets say I have a xslt stylesheet like the following: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
Let's say I have the following XML: <Account> <AccountExpirationDate>6/1/2009</AccountExpirationDate> </Account> I want to use
Let's say we have the following XML document: <root> <options> ... </options> <children> <child
Lets say I have following: library(XML) my.xml <- ' <tv> <show> <name>Star Trek TNG</name>
Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
I have made following relative layout in an xml file lets say add_relative_layout.xml <?xml
Lets say I have the following XML document: <response> <businessEntity> <ABN> <identifierValue></identifierValue> <isCurrentIndicator></isCurrentIndicator> <replacedIdentifierValue
Let's say we have the following XML: <root> <row> <column>row 1 col 1</column> <column>row

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.