?
Solved

xml to xml through xslt

Posted on 2014-12-14
3
Medium Priority
?
201 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

762 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