?
Solved

change name of xml tags with xslt if there other tag present.

Posted on 2015-01-22
2
Medium Priority
?
127 Views
Last Modified: 2015-01-22
Hi i Have the following xml, just have to change the the tag name based on the existence of another tag, could anyone please direct me how to do this in xslt.

current xml:
<Details>
                        <Cash>
                                    <TitleLogo> cash.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Approval>
                                                <Title>Who qualifies?</Title>
                                                <TitleLogo> eligible.gif</TitleLogo>
                                                <Header1>Who qualifies?</Header1>
                                                <Header2>When?</Header2>
                                                <Header3>How Much?</Header3>
                                                <Qualified>
                                                            <Person>
                                                                        <Names>\b.PAT, PEN, TAM, TON\b0.\n\n\n\n\n.</Names>
                                                                        <When>Dec 26, 2014</When>
                                                                        <HowMuch>$158.00 twice per month</HowMuch>
                                                            </Person>
                                                </Qualified>
                                                <Footer>\b.PAT, PEN, TAM, TON\b0.: To get this benefit, you and all members of your amily must be working and have earned income that we use to determine your monthly benefit.\n\n.</Footer>
                                    </Approval>
                        </Cash>
                        <Cash>
                                    <TitleLogo> cash.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Rejection>
                                                <Title>Who does not qualify?</Title>
                                                <TitleLogo>d:\Apps\MCI\SAT\Adobe\Corr\Logo\icon_elig_ineligible.gif</TitleLogo>
                                                <Header1>Who?</Header1>
                                                <Header2>Date of our decision?</Header2>
                                                <Description>
                                                            <Reason>
                                                                        <Value1>\b.TAM, TON\b0.</Value1>
                                                                        <Value2>December 16, 2014\n\n.</Value2>
                                                            </Reason>
                                                </Description>
                                                <Footer>\b.TAM, TON\b0.: Inside this letter you can learn more about the income and deductions we used to decide if you qualify</Footer>
                                    </Rejection>
                        </Cash>
<Details>

Open in new window



need to change to below xml using xslt. the 2nd <cash> tag should be changed to <cashR> if there is a <Rejection> tag exists.



<Details>
                        <Cash>
                                    <TitleLogo> cash.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Approval>
                                                <Title>Who qualifies?</Title>
                                                <TitleLogo> eligible.gif</TitleLogo>
                                                <Header1>Who qualifies?</Header1>
                                                <Header2>When?</Header2>
                                                <Header3>How Much?</Header3>
                                                <Qualified>
                                                            <Person>
                                                                        <Names>\b.PAT, PEN, TAM, TON\b0.\n\n\n\n\n.</Names>
                                                                        <When>Dec 26, 2014</When>
                                                                        <HowMuch>$158.00 twice per month</HowMuch>
                                                            </Person>
                                                </Qualified>
                                                <Footer>\b.PAT, PEN, TAM, TON\b0.: To get this benefit, you and all members of your amily must be working and have earned income that we use to determine your monthly benefit.\n\n.</Footer>
                                    </Approval>
                        </Cash>
                       [b] <CashR>[/b]
                                    <TitleLogo> cash.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Rejection>
                                                <Title>Who does not qualify?</Title>
                                                <TitleLogo>d:\Apps\MCI\SAT\Adobe\Corr\Logo\icon_elig_ineligible.gif</TitleLogo>
                                                <Header1>Who?</Header1>
                                                <Header2>Date of our decision?</Header2>
                                                <Description>
                                                            <Reason>
                                                                        <Value1>\b.TAM, TON\b0.</Value1>
                                                                        <Value2>December 16, 2014\n\n.</Value2>
                                                            </Reason>
                                                </Description>
                                                <Footer>\b.TAM, TON\b0.: Inside this letter you can learn more about the income and deductions we used to decide if you qualify</Footer>
                                    </Rejection>
                        [b]</CashR>[/b]
<Details>

Open in new window

0
Comment
Question by:sri1209
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 40564850
Try this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="Cash">
        <xsl:variable name="ename">
            <xsl:text>Cash</xsl:text>
            <xsl:if test="Rejection">
                <xsl:text>R</xsl:text>
            </xsl:if>
        </xsl:variable>
        <xsl:element name="{$ename}">
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window


The first template is an identity transform
The second has a conditional element name
0
 

Author Comment

by:sri1209
ID: 40564908
Thanks Geert Bormans, you are awesome. i have sent you an private email
 just to thank you for your help.
0

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 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