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

The Archive Base Latest Questions

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

I’m having trouble with writing a simple XSLT transform. Here is the XML data:

  • 0

I’m having trouble with writing a simple XSLT transform. Here is the XML data:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
  <lst name="params">
  </lst>
</lst>
<result name="response" numFound="2" start="0">
  <doc>
    <str name="Race">Elf</str>
    <int name="TraderKey">128</int>
    <str name="TraderName">TraderLato</str>
    <int name="CharacterName">Maleysh</int>
  </doc>
  <doc>
    <str name="Race">Human</str>
    <int name="TraderKey">62</int>
    <str name="TraderName">TraderSam</str>
    <int name="Comments">Farl</int>
  </doc>
</result>
</response>

I can’t modify the format of the XML coming in, and there will be lots and lots of nodes. I need to be able to write an XSLT 1.0 transform that will copy all the original XML but replace TraderName for certain TraderKey values. On any node that contains a TraderKey of 128, change the TraderName to “Trader Lato Carum”. Any that contains a TraderKey of 62, change the TraderName to “Trader Samson Vero”. I’ve never written an XSLT before, and have limited experience with XML, so this is my attempt to write an XSLT transform:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="response/result/doc/int[@name='TraderKey'][. = '128']>
   <xsl:value-of select="../TraderName"/>
   <xsl:text>Trader Lato Carum</xsl:text>
  </xsl:template>

  <xsl:template match="response/result/doc/int[@name='TraderKey'][. = '62']>
   <xsl:value-of select="../TraderName"/>
   <xsl:text>Trader Samson Vero</xsl:text>
  </xsl:template>

</xsl:stylesheet>

It doesn’t work at all and I’ve been hammering my head against a wall for the past hour. I don’t think this should be a difficult problem, what am I doing wrong?

Thanks
zoombini

  • 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-08T14:23:56+00:00Added an answer on June 8, 2026 at 2:23 pm

    You were on the right lines with the identity/copy pattern you had going on, you just need a bit of conditional output.

    Demo at this XMLPlayground (see output source)

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select='@*' />
            <xsl:apply-templates select='*' />
            <xsl:choose>
                <xsl:when test='@name = "TraderName" and preceding-sibling::*[@name = "TraderKey"] = 62'>
                    Trader Samson Vero
                </xsl:when>
                <xsl:when test='@name = "TraderName" and preceding-sibling::*[@name = "TraderKey"] = 128'>
                    Trader Lato Carum
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select='text()' />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:copy>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.