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

Subject: Re: [xsl] Output flat file results 2 nodes at a time?
From: Abel Braaksma <>
Date: Wed, 09 May 2007 17:00:22 +0200
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="";>
<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())"

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.

Current Thread