Guidance for complex XSLT
Hi - I'm working on parsing XML that is to be converted to text and submitted to FinCEN, who requires it to be in a very specific format. Basically, I will get an xml file with elements all arranged as siblings and their association with each other is based on order of appearance in the file. So I may have a file that looks like this:
Basically, the pseudo-code would look like this:
For each 2A
For each 2B before the next 2A
For each 3A before the next 2B
Output 3A; increment counter
For each 4A before the next 3A
Output 4A with above counter
The text will essentially need to be formatted in the order it is in the file, with some summary sections (after each 2B, for instance) . I'm having trouble figuring out how to loop over elements that follow a 3A, for example without looping over all the 4A records in the document. For each 3A, I will also need to keep a counter so I can output that with the text for the 3A section and associated 4A sections.
Originally, I had designed a series of <xsl:for-each> loops that would go through each of elements in the file and call the appropriate once for each, but I realized that will pick out all the elements in the file and not just the ones that appear beneath the relevant (parent) element that I want to see for that section.
Then, I considered using a catch-all <xsl:apply-templates/> so all the elements would be dealt with in the order they appear in the file. However, I don't see how I could use any kind of counter if I do it this way. (I understand I can't use an actual counter, but my contention was to call a template inside a for each loop and pass the position() as a parameter)
Please let me know if you have any suggestions on where to go with this. I have some XSL experience, but this is a bit different than what I'm used to.
Thanks in advance.
Last edited by Dracarnion; February 20th, 2013 at 02:21 PM..
Reason: added pseudo-code