Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT Code for complex XML document

Status
Not open for further replies.

ace0331

MIS
Jun 16, 2013
2
US
I have an xml document and I want to transform it to add an extra node element depending on some condition. Example given in the attachment. I want to write an .xsl program for the requirement "If a <report> does not have <department>, use the <department> of the immediate <Person> one level up". Basically I want to add <department> node if <report> does not have one, and that <department> value should be of the person one above it in my case. The values for

Tommy Trojans - Engineering
Ronald Jackson - Engineering
Justin Jones - Marketing

Can anyone please advice on how to do this??

Thanks,
Ace

 
I am a new user so I did not know about the attachment problem.
The code is below


<?xml version="1.0" encoding="UTF-8"?>
-<Data> -<People> -<Person id="1"> <name>John Taylor</name> <title>Manager</title> <department>Engineering</department> -<reports> -<report id="2"> <name>Tommy Trojans</name> <title>Engineer</title> </report> -<report id="3"> <name>Mike Lee</name> <title>Designer</title> <department>UI/UX</department> </report> -<report id="4"> <name>Ronald Jackson</name> <title>Engineer</title> </report> </reports> </Person> -<Person id="16"> <name>Maria Sanchez</name> <title>CEO</title> </Person> -<Person id="10"> <name>Matt Jones</name> <title>Director</title> <department>Marketing</department> -<reports> -<report id="9"> <name>Justin Jones</name> <title>Manager</title> </report> </reports> </Person> </People> -<Departments> -<Department> <name>Engineering</name> <rate max="100" min="10" type="hourly"/> <rate max="12000" min="1000" type="monthly"/> </Department> -<Department> <name>UI/UX</name> <rate max="50" min="12" type="hourly"/> <rate max="9000" min="1500" type="monthly"/> <rate max="2000" min="300" type="weekly"/> <rate max="100000" min="25000" type="yearly"/> </Department> -<Department> <name>Marketing</name> <rate max="90000" min="30000" type="yearly"/> <rate max="5000" min="500" type="weekly"/> </Department> </Departments> </Data>

Sorry for the in convenience.

 
Ok, I have cleaned up your input file (using the 'code' markup). Please be a bit more specific about your desired output.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<Data>
    <People>
        <Person id="1">
            <name>John Taylor</name>
            <title>Manager</title>
            <department>Engineering</department>
            <reports>
                <report id="2">
                    <name>Tommy Trojans</name>
                    <title>Engineer</title>
                </report>
                <report id="3">
                    <name>Mike Lee</name>
                    <title>Designer</title>
                    <department>UI/UX</department>
                </report>
                <report id="4">
                    <name>Ronald Jackson</name>
                    <title>Engineer</title>
                </report>
            </reports>
        </Person>
        <Person id="16">
            <name>Maria Sanchez</name>
            <title>CEO</title>
        </Person>
        <Person id="10">
            <name>Matt Jones</name>
            <title>Director</title>
            <department>Marketing</department>
            <reports>
                <report id="9">
                    <name>Justin Jones</name>
                    <title>Manager</title>
                </report>
            </reports>
        </Person>
    </People>
    <Departments>
        <Department>
            <name>Engineering</name>
            <rate max="100" min="10" type="hourly"/>
            <rate max="12000" min="1000" type="monthly"/>
        </Department>
        <Department>
            <name>UI/UX</name>
            <rate max="50" min="12" type="hourly"/>
            <rate max="9000" min="1500" type="monthly"/>
            <rate max="2000" min="300" type="weekly"/>
            <rate max="100000" min="25000" type="yearly"/>
        </Department>
        <Department>
            <name>Marketing</name>
            <rate max="90000" min="30000" type="yearly"/>
            <rate max="5000" min="500" type="weekly"/>
        </Department>
    </Departments>
</Data>

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top