XSLT Mapping

I am an amateur in XSLT transformation, could anyone please help me with the XSLT mapping, if possible please provide me the logic or a short code snippet and i can develop the rest. Attached are the source XML and the result XML.

MainDocument.xml is the source and MainDocument1.xml is the result after the mapping. I am trying to implement the result from source using XSLT.MainDocument1.xmlMainDocument.xml

It is actually a fairly tricky thing to do, to convert elements that are only related by their relative position into a heirarchy of elements. But the following should produce what you need. Let me know if there are any issues with it or if you have questions about it.

I got it working for single recordset but now i am trying to implement it for multiple Recordsets. Please check the attachement for detials. I have changed your code a bit but i am having difficulty in looping each record with Header as reference, so the result is that though the rest of the XML looks good, i am not able to achieve the same for Header and Trailer. Could you please suggest

However, it seems that you forgot to tell me what the expected output should look like when there are more than 1 <Record> element in the input. I can think of 2 possibilities off the top of my head, but you really need to tell me exactly what you want.

The first one, is that you would actually like a separate <message> element for each <Record> in the input. If so, you could try this...

The second possibility is that you want it pretty much like what you get now, but with the <HEADER> and <Trailer> records merged somehow. But if so, you still need to tell me how they should be merged. The <Trailer> record would be pretty straightforward as I would assume that you would just want the sum of all the individual <Trailer>/<NoofRecords> elements. But how to merge the date/time in the <HEADER>? Should it just pick the first date? Should it find the earliest (or latest) of all the dates? The following just takes the first <HEADER> in the input file...

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Ok, we probably need to build up the answer so that you can fully appreciate what is going on here... Note that following-sibling (as do a lot of XPath operators) is context-sensitive, so the result that we get depends on what element we are currently processing in the XML.

following-sibling::* - by itself will return to you all the elements that are at the same level as the current element that come after the current element in the document that have the same parent as the current element. Quick example...

If we are currently processing element <b> then following-sibling::* will return the set of elements <c> and <d>. Not <a> because it comes before <b> and not <e> or <f> because they have a different parent element.

following-sibling::ItemDetail - Does the same as the above but it will only return elements after the current element that are ItemDetail elements and have the same parent as the current element. Pretty straightforward.

(following-sibling::ItemDetail | following-sibling::ITEM) - Will return elements after the current element that are either ItemDetail or ITEM and have the same parent. We include ITEM elements so that we know where to "stop" including subsequent elements, other wise the very first ITEM would include ALL ItemDetails from the rest of the Record element. This is the tricky part of converting a file where elements are only related because they are next to each other, to a file where there is a proper heirarchy.

(following-sibling::ItemDetail | following-sibling::ITEM)[1] - Gets just the first element that is either ItemDetail or ITEM that follows the current element in the document.

(following-sibling::ItemDetail | following-sibling::ITEM)[1][name() = 'ItemDetail'] - This is the final piece of the puzzle... As above we select the first element that follows the current that is either ItemDetail or ITEM, and then "if" that element is an ItemDetail element, we select it, otherwise that element must be an ITEM element and we DON'T select it.

Basically, the above XSL works on recursion, after processing an ItemDetail element we look for the next ItemDetail element as call the same template again. So the above xpath selects the next ItemDetail element for each step of the recursion, but then if the next element is an ITEM element, nothing is selected which ends the recursion.

That's all quite long winded but hopefully you can follow and see what we are doing there. The <Address> processing is quite similar but a little bit simpler because ANY element that is NOT an Address terminates the recursion for including Addresses. However, for ItemDetails there is a little bit more work because (as one of the orders demonstrates) you can have an interleaving of ItemDetails and Address within the one ITEM, so we have to account for that.

Let me know if you have any further queues or require further clarification on the above.

This could be as detailed as possible, thanks. the most tricky part is the interleaving of ItemDetails and Address which require the following, which took quite sometime to figure it out. But one final thing i dont see any condition for the recursive occurence of ITEM. I suppose its something simple which i am missing. The issue is i am having problems debugging the XSLT with my editix xslt tool otherwise i shouldnt have given you this trouble.

No, you are right. There is nothing in there to deal with recursion for ITEM elements because there is no relationship between successive ITEM elements. One element in the input corresponds directly with one element in the output. I admit that the distinction is subtle between this and the ItemDetail/Address elements, but with these other elements one or two or more of them need to be gathered together and placed within the previous ITEM/ItemDetail parent element.

Purpose
To explain how to place a textual stamp on a PDF document. This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent. Watermark’s may be text or graph…

In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …