[XSLLIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Output fixed length records using mod operators to
> <xsl:if test="position()=last()"> tests if you are the last item. An alternative woiuld be to just put the code after the foreach except then you'd have to count the items again whereas inside the loop you have the total number of items as last() > <xsl:foreach select="(//*)[position()<= ((4000 last() )mod > 4)]"> <xsl:foreach select="(//*)[position()<= n] is a well known xslt1 trick way of doing what in xslt2 would be <xsl:foreach select="1 to n" (//*) just selects a bunch of nodes it doesn't matter which ones (so long as the input dociment has enough nodes) then (//*)[position()<= n] iterates n times, so in this case adds n blank $fields. So what's n? you want a number between 0 and 3 inclusive which when added to last() makes a multiple of 4, so if there were 13 items you want 3 so that the total is 16. "mod" is "clock arithmetic" but (here) using 4 rather than 12. "x is a multiple of 4" is "x = 0 mod 4" so the value you want for n is x as x + x = 0 mod 4. but if there are 13 items 13 mod 4 is 1, and while it's true that 1 = 3 mod 4, you definitely want to add three blank fields rather than delete your last item in order to get the right multiple. So you just need to make sure that the value will be positive. Adding a large multiple of 4 is just a trick way of doing that (not safe of course if there may be more than 4000 entries. A safer and perhaps clearer way but taking a few more keystrokes would be (4  (last() mod 4)) mod 4 so going back to the "13" example, that would be (4  (13 mod 4) mod 4 = (4  1) mod 4 = 3 instead of what i wrote which is ((4000 13 )mod 4 = 3987 mod 4 = 3 > <xsl:valueof select="$field"/> a blank field > </xsl:foreach> > </xsl:if> stuff. oh by the way as a test that you understand this one, you need to add the same thing to the po loop (using 2 instead of 4) to add a blank field in the case there is an odd number of po. Although in that case you don't need a loop it's just a simple if test that if last() mod 2 =1 add a blank field. David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This email has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________

PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our awardwinning XML IDE  Download a free trial today! Subscribe in XML format
