Subject: [xsl] Output flat file results 2 nodes at a time? From: Chris <ryder.roundabout@xxxxxxxxx> Date: Wed, 9 May 2007 09:00:14 -0400 |
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.
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] saxon:evaluate from exter, Michael Kay | Thread | Re: [xsl] Output flat file results , David Carlisle |
RE: [xsl] Embedding an SSI echo in , Michael Kay | Date | Re: [xsl] Output flat file results , David Carlisle |
Month |