Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 11th, 2008, 04:44 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl question for new user

<?xml version="1.0" encoding="utf-8" ?>
<?xml:stylesheet type="text/xsl"?>
<parent>
    <child col1="value1" col2="value2" col3="value3" .. col10="value10" />
    <child col1="valueA" col2="valueB" col3="valueC" .. col10="valueJ" />
...
        <child col1="value" ...col10="value" />
</parent>

How to get Values to display in rows, colums in alternate colors using xsl stylesheet. Any pointers?
<tr class="normal" bgcolor="green">
    <td class="normal">value1</td>
    <td class="normal">value2</td>
    <td class="normal">value3</td>
...
    <td class="normal">value10</td>
</tr>
<tr class="normal">
    <td class="normal">valueA</td>
    <td class="normal">valueB</td>
    <td class="normal">valueC</td>
...
    <td class="normal">valueJ</td>
</tr>
<tr class="normal" bgcolor="green">
    <td class="normal">value</td>
    ...
    <td class="normal">value</td>
</tr>
Thanks.
Reply With Quote
  #2 (permalink)  
Old May 11th, 2008, 04:54 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Use

<xsl:template match="child">
  <tr>
    <xsl:if test="position() mod 2 = 1">
      <xsl:attribute name="bgcolor">green</xsl:attribute>
    </xsl:if>
    <td class="normal"><xsl:value-of select="@col1"/></td>
    etc

(although I would have used a different CSS class, but that's a CSS question not an XSLT question).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old May 12th, 2008, 12:19 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Currently stylesheet used:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:n="http://www.w3.org">

<xsl:template match="/">
<html>
 <table>
...

<xsl:apply-templates select="//n:child" />
 </table>
</html>
</xsl:template>

<xsl:template match="child">

  <tr>
    <xsl:if test="position() mod 2 = 1">
      <xsl:attribute name="bgcolor">green</xsl:attribute>
    </xsl:if>
    <td class="normal"><xsl:value-of select="@col1"/></td>
  <tr>
</xsl:template>
</xsl:stylesheet>

I'm not seeing anything like "value1", "value", etc on IE 7.0 browser

old stylesheet used:
If xmlns:xsl="http://www.w3.org/TR/WD-xsl", the values are properly display (I'm not using test="position() mod 2 = 1" because it does not work with TR/WD-xsl
Please advise. Thanks.
Reply With Quote
  #4 (permalink)  
Old May 12th, 2008, 02:55 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Where does the prefix n and the namespace http://www.w3.org come from? I don't see these in your source document. If the element is in a namespace then the match should be match="n:child"; if it isn't in a namespace then the apply-templates should have select="//child".

Also, don't rely on the appearance of the HTML when displayed in a browser. Always look at the "source" HTML. In fact, a browser is the worst possible environment for developing and debugging XSLT.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old May 13th, 2008, 10:01 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Michael.
Works now with select="//child"
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL newbie question Someone2006 XSLT 4 October 10th, 2006 07:20 AM
xsl question bluisana XSLT 7 September 15th, 2005 01:34 AM
xsl:sort Question kwilliams XSLT 6 July 18th, 2005 08:39 AM
xsl:if question rdavisiii XSLT 2 March 30th, 2005 01:40 PM
XSL-FO Question gray XSLT 1 February 18th, 2005 11:31 AM



All times are GMT -4. The time now is 12:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.