[xsl] Newbie needs XSL help, 1-to-many xform, multi-value data items

Subject: [xsl] Newbie needs XSL help, 1-to-many xform, multi-value data items
From: thehulk@xxxxxxxxxxx
Date: Tue, 14 Dec 2010 18:41:13 +0000 (UTC)
This is a very general XSL question that applies to any processor. I am using Lotus Domino (Notes) embedded XSL processing in its LotusScript language on Domino 7.0.3, which is XSL 1.0 compliant. (Notes/Domino is a database which is not relational, so multi-value items are just fine.)

My problem is, i do not know how to create multiple elements from a single element with several multi-value child elements. (This is typical with Domino data.) For example, my Notes application might store multiple people and their cities into one Notes document. It might have some single-value data items on the document, and, a multi-value data item "MyNames", and, another multi-value item "MyCities". 

The order of the child nodes has meaning that is managed by the Notes application, so that the set of multi-value data items has the meaning of one two-dimensional array of data. 

When Domino outputs XML data, it preserves the order of the multiple values. So for example, I need to transform one "MyRecord" element into multiple "ATransaction" elements. Each "ATransaction"  has the same data from some parts of "MyRecord", along with only one "row" from the multi-value (multi-child) elements. 

If my application puts three people and their cities into one Notes document, Domino gives me XML much like this (simplified of course):

 <myDTD:MyRecord>
   <myDTD:BranchID> 12345 </myDTD:BranchID>
   <myDTD:RecordDate> November 3, 2009 </myDTD:RecordID>
   <myDTD:MyNames>
      <myDTD:Name> John Doe </myDTD:Name>
      <myDTD:Name> Rachel Roe </myDTD:Name>
      <myDTD:Name> Biff Jones </myDTD:Name>
   <myDTD:/MyNames>
   <myDTD:MyCities>
      <myDTD:City> Kalamazoo </myDTD:City>
      <myDTD:City> Katmandu </myDTD:City>
      <myDTD:City> Timbuktu </myDTD:City>
   <myDTD:/MyCities>
 <myDTD:/MyRecord>

I need to turn that one "MyRecord" element into multiple "ATransaction" elements (three of them, in this case). Each of them has certain data from "MyRecord", along with only one value from each of the multi-child elements "MyNames" and "MyCities". 

For the above example, the result I need is like this:

 <otherDTD:Transactions>
   <otherDTD:ATransaction>
     <otherDTD:Branch> 12345 </otherDTD:Branch>
     <otherDTD:When> November 3, 2009 </otherDTD:When>
     <otherDTD:Who> JohnDoe </otherDTD:Who>
     <otherDTD:Where> Kalamazoo </otherDTD:Where>
   </otherDTD:ATransaction>
   <otherDTD:ATransaction>
     <otherDTD:Branch> 12345 </otherDTD:Branch>
     <otherDTD:When> November 3, 2009 </otherDTD:When>
     <otherDTD:Who> Rachel Roe </otherDTD:Who>
     <otherDTD:Where> Katmandu </otherDTD:Where>
   </otherDTD:ATransaction>
   <otherDTD:ATransaction>
     <otherDTD:Branch> 12345 </otherDTD:Branch>
     <otherDTD:When> November 3, 2009 </otherDTD:When>
     <otherDTD:Who> Biff Jones </otherDTD:Who>
     <otherDTD:Where> Timbuktu </otherDTD:Where>
   </otherDTD:ATransaction>
 </otherDTD:Transactions>

Current Thread