Loop through data fields in node and format output as zebra striped table
I want to output all fields on a node that have content in a table with alternate row background color. I don't see how I can use a for-each loop on data fields within a single node. Originally I used a session variable for this but suddenly that didn't work anymore - I have trouble getting a session variable value stored. So how can I simulate a counter value to use a mod 2 on so I can control the background color, anyone?
You seem to have a suggestion for xslt that did not show up in your response.
But I tried the CSS tip and it works wondrously - in all browsers except IE 7 and 8.
I cannot believe they don't support that CSS markup at all, do you know if there is some trick to it in IE? If this actually doesn't work in IE I need another solution.
P.S. I always keep my css markup in a separate stylesheet.
Your xslt is exactly what I tried to use, but you can't do a for-each on data fields within a node, can you?
In my case a document type called Destination has like 15 string fields. These are to be outputted in a simple table, one field per row, if they contain text.
I have seen another solution wich uses an index parameter to a secondary xsl:template in order to achieve counter behaviour. But I have to treat my fields in if-tags, so I would need a separate secondary template for each field in order to make it work.
Loop through data fields in node and format output as zebra striped table
I want to output all fields on a node that have content in a table with alternate row background color. I don't see how I can use a for-each loop on data fields within a single node. Originally I used a session variable for this but suddenly that didn't work anymore - I have trouble getting a session variable value stored. So how can I simulate a counter value to use a mod 2 on so I can control the background color, anyone?
Hi Siw,
If you are using xsl you can just use the position() in the for-each loop like this:
Another way might be to use CSS to style up your table: http://www.w3.org/Style/Examples/007/evenodd.
Hope that helps,
Sascha
Hi Sascha,
You seem to have a suggestion for xslt that did not show up in your response.
But I tried the CSS tip and it works wondrously - in all browsers except IE 7 and 8.
I cannot believe they don't support that CSS markup at all, do you know if there is some trick to it in IE?
If this actually doesn't work in IE I need another solution.
P.S. I always keep my css markup in a separate stylesheet.
Hi Siw,
ups, just found out here (http://msdn.microsoft.com/en-us/library/cc351024(VS.85).aspx) that nth-child won't work with IE, bugger, didn't know that...
You could try it out with jQuery: http://blog.darkhax.com/2010/01/17/making-nth-child-work-everywhere.
Very odd my xslt code didn't come through, anyway here it is:
Hope that helps,
Sascha
Hi Sascha,
I really appreciate fast responses :-)
Your xslt is exactly what I tried to use, but you can't do a for-each on data fields within a node, can you?
In my case a document type called Destination has like 15 string fields. These are to be outputted in a simple table, one field per row, if they contain text.
I have seen another solution wich uses an index parameter to a secondary xsl:template in order to achieve counter behaviour. But I have to treat my fields in if-tags, so I would need a separate secondary template for each field in order to make it work.
I'll have a look at your Jquery example.
Why would you not be able to do a for-each on data nodes (I'm assuming that you are using umbraco 4.0.x and not 4.5)?
You should be able to get just the fields with data in them like this:
Then the position() mod 2 would work on the fileds with data.
Dear Morten,
My xsl knowledge is sadly faulty. Your suggestion is perfect. Thanks a bunch and have a nice day!
EDIT:
Mortens suggestion solved my problem.
is working on a reply...