Change element name to child element text value

Posted on 2005-04-15
Last Modified: 2013-11-19
I have the following incoming XML document which I need to transform using XSL to another XML document.

        <COMPLETED_DATE>15-Apr-2005 00:00:00</COMPLETED_DATE>
      <COMPLETED_DATE>15-Apr-2005 00:00:00</COMPLETED_DATE>

The resulting XML Document needs to look like this:
        <DATE>15-Apr-2005 00:00:00</DATE>
      <DATE>15-Apr-2005 00:00:00</DATE>

I can get everything transformed correctly with the exception of the EVENT_TYPE element.  I need to replace it's parent element name with it's text node value.  No hardcoding of the parent element name (EVENTS) can be used since the name of the parent element can change.


Question by:trudyhlittle
    1 Comment
    LVL 23

    Accepted Solution

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output method="xml" version="1.0" />
    <xsl:template match="@* | node()">
    <xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>

    <xsl:template match="EVENT_TYPE" />

    <xsl:template match="EVENTS">
    <xsl:element name="{EVENT_TYPE}"><xsl:apply-templates select="@* | node()" /></xsl:element>

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

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


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Forbidden errors 5 95
    video playback resume on webpages 2 52
    Specific format 21 109
    Problem to event 3 27
    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    The viewer will learn how to count occurrences of each item in an array.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now