I've been provided an SML file where the designer (not in my company, so I have no control over this) has created some data that I need to consume; but they setup enumerated tags, so I'm having a difficult time creating a loop to read the data.
Their code looks like
<Root>
<Subjects>
<...more XML Data>
<Data>
<...other XML Data>
<Demographic_Information>
<Age1>33</Age1>
<Age2>66</Age2>
<Age3 />
<Age4 />
<Age5 />
<Age6 />
<Age7 />
<Age8 />
<Age9 />
<Age10 />
<Gender1>M</Gender1>
<Gender2>F</Gender2>
<Gender3 />
<Gender4 />
<Gender5 />
<Gender6 />
<Gender7 />
<Gender8 />
<Gender9 />
<Gender10 />
<Race1>W</Race1>
<Race2>H</Race2>
<Race3 />
<Race4 />
<Race5 />
<Race6 />
<Race7 />
<Race8 />
<Race9 />
<Race10 />
</Demographic_Information>
</...other XML Data>
</Data>
</...more XML Data>
</Subjects>
</Root>
I just need to loop through this, and ensure that Age1, Gender1, and Race1 go into my data like
<Person subject="1">
<Age>33</Age>
<Gender>M</Gender>
<Race>W</Race>
</Person>
<Person subject="2">
<Age>66</Age>
<Gender>F</Gender>
<Race>A</Race>
</Person>
This is a subset of data inside a larger set, but I need to get it into this format if possible. I'm sure it can be done, I just don't know how to go about it.
My XSLT is version 1.0 in Microsoft Visual Studio 2008. I start with
<xsl:template match="/Root/Subjects">
***Modified to provide a better sample of my issue.
Here's a quick stab that works - I'm going to continue to look at this to find efficiencies, but I wanted to get you an answer.
EDIT: thanks to @MartinHonnen for a nice simplification.
When this XSLT:
...is applied to the provided source XML:
...the wanted result is produced:
The following will do. But perhaps not the fastest solution.
another alternative: