[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Counting or Modulus calculations in XSL

Subject: Re: Counting or Modulus calculations in XSL
From: Joe English <jenglish@xxxxxxxxxxxxx>
Date: Fri, 30 Jun 2000 13:59:10 -0700
modulus calculation
ath@xxxxxx wrote:
>
> Then I have to parse it with XSL into a two column table so that <info> wit
> odd-number position goes into the left column and the even number <info>
> into the right column, two <info>'s in each row.
> All suggestions welcome. I can only make it appear in one column, one <info
> in each row.  Wouldn't be so tricky if the number of <info> didn't change.


Warren Hedley <w.hedley@xxxxxxxxxxxxxx> replied:
>
> The very first question in the FAQ! Come on, put some effort in.
> http://freespace.virgin.net/b.pawson/xsl/N961.html

That approach would work to build a table with a
fixed number of *rows* and the number of *columns*
depending on the number of items; to do it the other
way around (fixed number of columns, variable number
of rows), you can use call-template recursively:


    template make-row:
	parameter cells = count(child::ITEM);	-- total #cells --
    	parameter cols  = 2;			-- desired #columns --
	parameter start = 1;			-- first cell in this row --
	parameter end   = $start + $cols;	-- last cell in this row --
	element "TR":
	    for-each child::ITEM[position() >= $start and position() < $end ]:
	    	element "TD":
		    apply-templates;
		end element;
	    end for-each;
	end element;
	if $end <= $cells:
	    call-template make-row
		with-parameters start = $end, cols = $cols;
	end if;
    end template.


(Pardon the pseudosyntax; please add punctuation as needed
to make this valid XSL).

Another approach, if you're using SAXON, is to use saxon:group
with group-by="floor((position() - 1) div $cols)".


--Joe English

  jenglish@xxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.