Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2008, 04:44 PM
Registered User
 
Join Date: May 2008
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.
 
Old May 11th, 2008, 04:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 12th, 2008, 12:19 PM
Registered User
 
Join Date: May 2008
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.
 
Old May 12th, 2008, 02:55 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 13th, 2008, 10:01 PM
Registered User
 
Join Date: May 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





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





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