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

  • Home
  • SEARCH
  • 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 5937541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:33:21+00:00 2026-05-22T15:33:21+00:00

I’ve been given the task to look into using xsl to update a few

  • 0

I’ve been given the task to look into using xsl to update a few of our xml documents at work, and I have been looking at some tutorials for xsl, though I have yet to come across what I would ideally be looking for…

Since im not at work, wheres a small example of heres what im looking for:

<?xml version="1.0" encoding="UTF-8"?>
<application>
    <id>627</id>
    <name>application1</name>
    <url>www.application.com</url>
</application>

I would need to convert this to:

<?xml version="1.0" encoding="UTF-8"?>
<application>
    <id>627</id>
    <application_name>application1</application_name>
    <url>www.application.com</url>
</application>

Now from the examples and tutorials I’ve seen I could do this with a hard coded xsl sheet looking like so:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template match="/">
        <application>
        <xsl:apply-templates/>
        </application>
    </xsl:template> 
    <xsl:template match="id">
        <id>
        <xsl:value-of select="id"/>
        <xsl:apply-templates/>
        </id>
     </xsl:template>
     <xsl:template match="name">
        <application_name>
        <xsl:value-of select="name"/>
        <xsl:apply-templates/>
        </application_name>
     </xsl:template>
     <xsl:template match="url">
        <url>
        <xsl:value-of select="url"/>
        <xsl:apply-templates/>
        </url>
     </xsl:template>
</xsl:stylesheet>

But this really wouldnt be practical since we have near 50 different xml documents that might need changing, and so I was really looking for a catch all template that I can use, and then only override the appropriate element that needs to be changed.

Does this functionality exist in xsl?

  • 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-22T15:33:22+00:00Added an answer on May 22, 2026 at 3:33 pm

    Let me see if I understand what you need. The first template rule in the transform below is called identity transform processes all nodes by copying them, and can be overridden for individual elements, attributes, comments, processing instructions, or text nodes. In your case, I’ve just overridden for the element name.


    XSLT 1.0 tested under Saxon 6.5.5

    <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:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="name">
            <xsl:variable name="parent" select="name(parent::*[1])"/>
            <xsl:variable name="node" select="local-name()"/>
            <xsl:element name="{$parent}_{$node}">
                <xsl:apply-templates select="node()|@*"/>
            </xsl:element>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Applied on this input:

    <?xml version="1.0" encoding="UTF-8"?>
    <anyapplication>
        <id>627</id>
        <name>application1</name>
        <url>www.application.com</url>
    </anyapplication>
    

    Produces:

    <?xml version="1.0" encoding="UTF-8"?>
    <anyapplication>
        <id>627</id>
        <anyapplication_name>application1</anyapplication_name>
        <url>www.application.com</url>
    </anyapplication>
    
    • 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
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.