473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to generate striped table?

2
Hi everybody!

this is my first post here but I would like to start saying thank you 'cos even if I never wrote here I read so many useful posts!

Here is the issue coming...

I need to generate an html table for a prods catalogue starting from xml.

So, it has been easy to get the data I need but it seems to be not that easy to style it up!

I'll let the code speak for me now...

Expand|Select|Wrap|Line Numbers
  1. <table>
  2.     <xsl:for-each select="Fields/field">
  3.         <xsl:if test="not(contains(pName, 'blabla') or pValue = '' or @hiddenField='true')">
  4.             <tr>
  5.                 <td class="label">
  6.                     <xsl:text> • </xsl:text>
  7.                     <xsl:value-of select="pName"/>
  8.                 </td>
  9.                 <td class="value">
  10.                     <xsl:value-of select="pValue"/>
  11.                 </td>
  12.             </tr>
  13.         </xsl:if>
  14.     </xsl:for-each>
  15. </table>
  16.  
so the DREAM is to have something like a counter to find out if a row is odd or even and then to give it a class (like tr class=evenrow ..)

Of course the first idea I had was to check the value of position() of a node but since I dont get all the nodes (because of the if condition) the value i get it's useless...

Does anybody know some trick or just some easy solution for this?
I know it probably can be a really stupid question for you but I'm a newbie with xsl and xpath...I'm founding it really exciting and in few days i learnt a lot but...not enough to solve this :)

thanks in advance for any help!

Ale
Feb 8 '08 #1
2 1192
jkmyoung
2,057 Expert 2GB
You could have something like
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="position">
  2.   <xsl:choose>
  3.      <xsl:when test="position() mod 2 = 0">evenrow</xsl:when>
  4.      <xsl:otherwise>oddrow</xsl:otherwise>
  5.   </xsl:choose>
  6. </xsl:variable>
  7.  
  8. <tr class="{$position}"/>
  9.  
Note, use of braces {} in the attribute that tells the processor that this is an xpath to be evaluated as opposed to a string.

If you want this only on your filtered rows, you have to move the if test to the for-each like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="Fields/field[not(contains(pName, 'blabla') or pValue = '' or @hiddenField='true')]">
  2.  
and get rid of the if element.
Feb 8 '08 #2
alepac
2
you cant imagine how stupid (and grateful to you) i feel!

i had the key! i could get the position to filter my table elems but...i was not filtering them all together in the for-each! that's it!!! there was no reason to have a for-each and then a xsl if after! having them together i get just the elements I want and THEN i can use the position element! I obviously need to learn a little more xpath stuff :D

I was looking for a really difficult solution for a really difficult problem when I could make the problem....really easy! Thanks for the help! thanks a lot!!! :)



and...thank you again!!! :)
Feb 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Terri | last post by:
I'd I have a problem I'd like to post CREATE TABLE and INSERT statements that will create my table and insert data into the table. I can use the scripting feature in Enterprise Manager to...
1
by: muesliflakes | last post by:
I'm trying to generate a normalized XML document out of SQL server that reflects the data structure of a table. Eg. This is what I would like to get <table name='MtFeedback'> <field...
6
by: Sebastien | last post by:
Hi, I am building a products database, linking sales and production. Each part has a unique sales Stock Code and Production Number. The sales stock code is a combination of letters and numbers...
2
by: Keith A. Rowe | last post by:
I have developed apps on scores of platforms for 25 years. Each of these platforms have supported a "quick, but not so dirty" utility for code table maintenance. For example, I have a States...
5
by: Hunter Hillegas | last post by:
I have a CSV file with 400,000 lines of email mailing list information that I need to migrate to a new PostgreSQL database. Each line has all the info I need except a PK (I usually use an int4...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
15
by: Orchid | last post by:
Hello, I am looking to generate a unique ID field on MS. Access. The ID is with 10 digits with the combination of 5 Letters from the 26 letters and 5 Numbers from 1 to 9. The letters and numbers...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
3
by: peanutbuttercravings | last post by:
I don't know much about db2 but I need to move a filesystem from a striped logical volume to raid5? And are there any implications moving the filesystems which hold db2 tables to sharks? Is there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.