xsl-list
[Top] [All Lists]

[xsl] Output flat file results 2 nodes at a time?

2007-05-09 06:00:42
Hi list,

I tried searching for similar posts, but I've been unable to locate
anything. If anyone can point me to an archive, I'd greatly appreciate
it.

For particulars, I'm using XSLT 1.0 and Xalan to process.

I need to take the following XML document (a shipping delivery) and
output as a fixed length file.  The fixed length file has expected
repetitions within it, as follows:
1) The first output record -- REC1 -- is the shipping header.
2) The second output line(s) -- REC2 --are the purchase order(s). Each
line of text will contain least one and up to two purchase orders.
3) The final output line(s) --REC3 -- are the containers. Each line of
text will contain at least one and up to four containers.

Go given a single shipment referencing three total purchase orders and
containing seven total boxes (allocated against specific POs):

The XML source:
<shipment>
 <header>
   <shipmentId>DELIVERY 1</shipmentId>
 </header>
 <detail>
   <po>PO 1</po>
   <containers>
     <box>BOX 1</box>
     <box>BOX 2</box>
   </containers>
 </detail>
 <detail>
   <po>PO 2</po>
   <containers>
     <box>BOX 3</box>
     <box>BOX 4</box>
     <box>BOX 5</box>
   </containers>
 </detail>
 <detail>
   <po>PO 3</po>
   <containers>
     <box>BOX 6</box>
     <box>BOX 7</box>
   </containers>
 </detail>
</shipment>

The desired output is:
REC1*DELIVERY 1
REC2*PO 1*PO 2
REC2*PO 3*
REC3*BOX 1*BOX 2*BOX 3*BOX 4
REC3*BOX 5*BOX 6*BOX 7

I'm getting stuck on either a for-each, apply-templates or recursive
call over the <po> elements to output 2 per line of text, or over the
<box> elements to output 4 per line of text.

My gut is telling me to use recursion, and I'm thinking of passing a
string as a param that's added to in each pass (i.e. string +
newstring), but I'm drawing blanks on how to break each one into
chunks of 2 or 4.  And how to address for non-multiples of 2 or 4.

I've done some basic XSLT before, but this one is a real challenge for
me.  Any and all suggestions welcomed!

Thanks,
Chris

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--