[xsl] How to map XML to XML according to element values

Subject: [xsl] How to map XML to XML according to element values
From: Roy_Lu@xxxxxxxxxxxxxxxx
Date: Mon, 26 Nov 2001 10:25:21 -0800
Hi, I am new to the list and I have searched the archive but couldn't find
an answer.

I have the following XML,

<Company>
  <Departments>
    <Department>
      <DeptCode>D1</DeptCode>
      <Name>Engineering</Id>
    </Department>
    <Department>
      <DeptCode>D2</DeptCode>
      <Name>Custom Support</Name>
    </Department>
  </Departments>
  <Employees>
    <Employee>
      <EmpNo>E1</EmpNo>
      <Name>John Smith</Name>
      <Dept>D1</Dept>
    </Employee>
    <Employee>
      <EmpNo>E2</EmpNo>
      <Name>Mary Johnson</Name>
      <Dept>D2</Dept>
    </Employee>
    <Employee>
      <EmpNo>E3</EmpNo>
      <Name>Tom Baker</Name>
      <Dept>D1</Dept>
    </Employee>
  </Employees>
</Company>

I would like to transform it into another XML, by matching <DeptCode> in <Department> to <Dept> in <Employee>.  The output XML should look like:

<Company>
  <Departments>
    <Department>
      <DeptCode>D1</DeptCode>
      <Name>Engineering</Id>
      <Employee>
        <EmpNo>E1</EmpNo>
        <Name>John Smith</Name>
      </Employee>
      <Employee>
        <EmpNo>E3</EmpNo>
        <Name>Tom Baker</Name>
      </Employee>
    </Department>
    <Department>
      <DeptCode>D2</DeptCode>
      <Name>Custom Support</Name>
      <Employee>
        <EmpNo>E2</EmpNo>
        <Name>Mary Johnson</Name>
      </Employee>
    </Department>
  </Departments>
</Company>

Can someone give me an advice? Thanks a lot.

Roy



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread