Posts

Showing posts from November, 2017

Using accumulators to number items in a streamable way

Both in XSLT 1 and 2 you can use the powerful xsl:number instruction to count and number nodes. Of course, that instruction is also supported in XSLT 3 , however, if you want to use xsl:number with streaming then you will find that the streamability of that instruction is rather restricted:   xsl:number  can be used for formatting of numbers supplied directly using the  value  attribute, and also for numbering of nodes in a non-streamed document, but it cannot be used for numbering streamed nodes On the other hand, you will see in this article that using accumulators you can write a stylesheet to count and number nodes in XSLT 3 in a way that works with both streaming and non-streaming. As an example let's take a recent post on StackOverflow that wants to count and number the row and col elements in the input sample and transform it to a flat structure with the row  and col index as attributes on a data element: Using accumulators we can continue to use pa