xsl-list
[Top] [All Lists]

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

2007-05-09 06:59:16
Hi Chris,

Perhaps this is what you are after? It outputs what you specified.

(ah, I see that David beat me to it with a much shorter approach ;)

Cheers,
Abel

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

   <xsl:output method="text" />

   <xsl:template match="/shipment" >
       <xsl:apply-templates select="header" />
       <xsl:apply-templates select="detail" />
       <xsl:apply-templates select="detail/containers/box" />
   </xsl:template>

   <xsl:template match="header">
       <xsl:text>REC1*</xsl:text>
       <xsl:value-of select="shipmentId"/>
       <xsl:text>&#xA;</xsl:text>
   </xsl:template>

   <xsl:template match="detail" />

   <xsl:template match="detail[position() mod 2 != 0]" >
       <xsl:text>REC2</xsl:text>
<xsl:apply-templates select="po | following-sibling::detail[1]/po" />
   </xsl:template>

   <xsl:template match="po" >
       <xsl:text>*</xsl:text>
       <xsl:value-of select="."/>
       <xsl:if test="position() mod 2 = 0 or position() = last()">
           <xsl:text>&#xA;</xsl:text>
       </xsl:if>
   </xsl:template>

   <xsl:template match="box" >
       <xsl:if test="position() mod 4 = 1">REC3</xsl:if>
       <xsl:text>*</xsl:text>
       <xsl:value-of select="."/>
       <xsl:if test="position() mod 4 = 0">
           <xsl:text>&#xA;</xsl:text>
       </xsl:if>
</xsl:template> </xsl:stylesheet>


Chris wrote:

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.



--~------------------------------------------------------------------
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>
--~--