This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
The XSLT transformation I'm working on is crucial for my project, and it's hampering progress as I'm not familiar with XSLT. I've managed to get my xsl stylesheet to do some of the things I want it to do, but not all. I'd just like to get it working without having to go though an XSLT book for now as I'm already reading two other books.
Anyway, to the point.
A. Combining apply-templates SOLVED: Okay, I've just discovered xsl:call-template.
And three separate matching templates. Surely there must be a way to just have one xsl:apply-templates statement.
B. Alternating rows
1. I need to read words <word>aWord</word> from an XML file, but I will never know how many words there will be
2. The words will go into an html table, a maximum of five per row.
3. Rows have alternating colors
If I had to write a program in Java which printed five words per line, I'd just do something like
So I'm assuming I could also use mod % 5 to create a new table row and perhaps some kind of boolean value to indicate whether we're working with odd or even rows for colors. Could someone help me out?
I found the answer on stackoverflow, but it took me a while to figure it out.
So here's my code:
I sat pondering for a while and couldn't figure out the math for $current-pos. So here's how it works:
1. Let's say we have 20 word nodes.
2. The first for-each will select nodes 1, 6, 11, and 16 and create a new row with each iteration.
3. Here's where I was confused: The above statement generates a tree of four nodes, so position() will actually return 1,2,3, and 4.
4. $current-pos must be then multiplied by 5, and a 1 must be added to match the real current position. 1 is 6, 2 is 11, 3 is 16. 4 is 21.
5. The next conditional for-each iterates through nodes [ 1-5][6-10][11-15][16-20]