Flattening out an XML document

I'm working with an HR system and trying to deal with an XML document
that contains a bunch of personal data (unique to the person) and one or
more sets of job data (a person can be hired more than once), all
expressed in a single XML document. I want to flatten out the multiple
job data parts by building a much larger XML document. (This may not
make sense by itself, but it's part of a larger project.)

Dummying up an example to illustrate, a hire document could look like:

The interesting parts here are just that there is a bunch of personal
data (first name, last name, birthdate, etc.) listed. For this person,
there are two job entries, denoted by NIU_HR_EDIR_JOB, and made unique
by the EMPL_RCD component (0, 1, etc.) of each NIU_HR_EDIR_JOB node.

What I want to do is match at the <modify> level, and build <modify> sections
for each of the NIU_HR_EDIR_JOB attributes, containing a fully described
personal+job entry, using the personal data from the source document,
and merging in each job entry, so that I'd have something like this:

I believe that my best bet for handling one or more NIU_HR_EDIR_JOB
sections is using <xsl:for-each>, but since the NIU_HR_EDIR_JOB info
is burried within the <modify>, I'm having trouble getting the rest
of the document, and getting to only (each) one of the NIU_HR_EDIR_JOB
nodes. The closest I've come, so far is making the copies of most
things (I'm losing the <modify> somewhere), and failing to strip
out the extra NIU_HR_EDIR_JOB nodes as it does so. Several hours of
Googling have not turned up a solution.

I know that this is close, but I can't quite see it. I also know that
I've been looking at it for too long, and I'm probably missing something
obvious. I'm hoping that somebody can point out my error here. Solutions,
suggestions, or ideas appreciated. Please post followups. The email
address is valid, but I'd rather see followups posted here if possible.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!