Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

xml to xml through xslt

Posted on 2014-12-14
3
Medium Priority
?
209 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
[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
3 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 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 36

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

604 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