Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Raju Bade 2 posts 22 karma points
    May 21, 2015 @ 22:52
    Raju Bade
    0

    xml to xml using xslt

    Dear Friends,

    Can someone help me translating one xml to another xml using xslt.

    Please see below input xml which has name and valueAsString elements where it determine to go what level of element.

    Input xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <outputMessage>
        <offers>
            <attributes>
                <name>type</name>
                <valueAsString>pkg</valueAsString>
            </attributes>
            <attributes>
                <name>name</name>
                <valueAsString>First package</valueAsString>
            </attributes>
            <attributes>
                <name>id</name>
                <valueAsString>P1</valueAsString>
            </attributes>
        </offers>
        <offers>
            <attributes>
                <name>type</name>
                <valueAsString>grp</valueAsString>
            </attributes>
            <attributes>
                <name>parent_id</name>
                <valueAsString>P1</valueAsString>
            </attributes>
            <attributes>
                <name>id</name>
                <valueAsString>G1</valueAsString>
            </attributes>
        </offers>
        <offers>
            <attributes>
                <name>type</name>
                <valueAsString>ofr</valueAsString>
                <valueDataType>string</valueDataType>
            </attributes>
            <attributes>
                <name>parent_id</name>
                <valueAsString>P1</valueAsString>
                    </attributes>
            <attributes>
                <name>id</name>
                <valueAsString>OFR1</valueAsString>
                </attributes>
        </offers>
        <offers>
            <attributes>
                <name>type</name>
                <valueAsString>ofr</valueAsString>
            </attributes>
            <attributes>
                <name>parent_id</name>
                <valueAsString>G1</valueAsString>
            </attributes>
            <attributes>
                <name>id</name>
                <valueAsString>OFR2</valueAsString>
            </attributes>
        </offers>
        <offers>
            <attributes>
                <name>type</name>
                <valueAsString>ofr</valueAsString>
            </attributes>
            <attributes>
                <name>parent_id</name>
                <valueAsString>null</valueAsString>
            </attributes>
            <attributes>
                <name>id</name>
                <valueAsString>OFR3</valueAsString>
            </attributes>
        </offers>
    </outputMessage>
    

    Output xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <offers>
        <offer>
        <id>OFR3</id>   
        </offer>
        <package ID="P1">
            <groups>
                <group ID="G1">
                    <offer>
                    <ID>OFR2</ID>
                    </offer>
                </group>
            </groups>
            <offer>OFR1</offer>
        </package>
    </offers>
    

    Thanks in Advance, Raju

Please Sign in or register to post replies

Write your reply to:

Draft