xsl-list
[Top] [All Lists]

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

2007-05-09 08:02:48
David Carlisle wrote:
(ah, I see that David beat me to it with a much shorter approach ;)

Nah, that was the long approach, the shorter approach is just to use a
single xpath 2 expression:



<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>

 <xsl:template match="shipment">
   <xsl:value-of select="'&#10;REC1*',header/string(shipmentId),
                         detail/po/(if(position() mod 2 = 1) then '&#10;REC2*' 
else '*', string()),
                         detail/containers/box/(if(position() mod 4 = 1) then 
'&#10;REC3*' else '*',string())"
                 separator=""/>
 </xsl:template>
</xsl:stylesheet>


That's a beauty!
Reading it, I much like the shortcut of deatil/po(if ...) etc. I then hoped, that the if-statement could be replaced with a predicate, but that wouldn't work, as the position() will then be about the sequence and not the element, like here:

detail/po/(('*', '&#10;REC2*')[position() mod 2 + 1], string())

and even if it worked, it'd be questionable whether it'd be clearer than the if-syntax.

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