• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

xml to xml through xslt


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
                                                <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>

to the below xml using an xslt

                                                <Caption4>=Net income<Caption4>
                                                <Caption5>Income limit to qualify</Caption5>

Thanks in Advance
  • 2
1 Solution
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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:apply-templates select="@*|node()" />

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

Open in new window

reddytsiAuthor Commented:
Thank you mccarl
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now