Solved

xml to xml through xslt

Posted on 2014-12-14
3
183 Views
Last Modified: 2014-12-15
Hi,

i am trying to use an xslt to convert .xml to .xml , but i am not sure how to


How do i change the following xml
<FS>
<Captions>
                                                <Caption id="1">Income</Caption>
                                                <Caption id="2">-Deductions</Caption>
                                                <Caption id="3">-Expenses</Caption>
                                                <Caption id="4">=Net income</Caption>
                                                <Caption id="5">Income limit to qualify</Caption>
  </Captions>
</FS>

to the below xml using an xslt

<FS>
<Captions>
                                                <Caption1>Income</Caption1>
                                                <Caption2>-Deductions</Caption2>
                                                <Caption3>-Expenses</Caption3>
                                                <Caption4>=Net income<Caption4>
                                                <Caption5>Income limit to qualify</Caption5>
   </Captions>
</FS>


Thanks in Advance
reddtsi
0
Comment
Question by:reddytsi
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 40499405
This is a fairly general solution, that will transform "Caption" elements in any context. You can, of course, tweak it to be more specific if required.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />

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

    <xsl:template match="Caption">
        <xsl:element name="{concat('Caption', @id)}">
            <xsl:apply-templates select="node()" />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:reddytsi
ID: 40499450
Thank you mccarl
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40499451
You're welcome!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
I'd like to talk about something that is near and dear to my heart: build systems. Without them, building software is all about compiling locally, with software versions everywhere. It can be a mess. Today we are going to discuss building a small di…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 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

23 Experts available now in Live!

Get 1:1 Help Now