>I basically need to reset the "position counter" for each new customer and increment it until there are no more records left for that customer. Then reset the counter and start again for the next customer etc etc...
No, that's what you would need to do if you were using a procedural programming language. You can't use the same kind of thinking in a functional programming language: and usually you don't need to. You're instinctively thinking about the problem algorithmically rather than functionally.
You first need to group securities by customer: in XSLT 2.0 use xsl:for-each-group, in 1.0 use Muenchian grouping (
www.jenitennison.com/xslt/grouping). Then you need to iterate over the resulting customers. In this grouped iteration position() will give you the current customer number and can be used to compute the x coordinate in your graphic.
Schematically, in XSLT 2.0:
<xsl:for-each-group select="Security" group-by="PortfolioID">
<xsl:variable name="x" select="position()*0.25"/>
<xsl:for-each select="current-group()">
-- draw a rectangle --
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference