XML, XSL, CSS attribute issue

Discussion in 'XML' started by Pradeep, Jan 16, 2008.

  1. Pradeep

    Pradeep Guest

    I have a following XML file, XSL file and CSS file.

    I am facing one problem , that ITEM rows are not displayed in proper
    color (RED) as mentioned in css file for .row1...... Same thing works
    well if the table is created in <xsl:template match="/"> but doesn't
    work for table created in <xsl:template match="ITEMLIST">.

    ------------------------------------------------------------------------------------------------------
    XML file ( name myxml.xml)
    ------------------------------------------------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="myxsl.xsl"?>
    <ITEMLIST>
    <ITEM>
    <NAME> Item1 </NAME>
    <PRICE> 500 </PRICE>
    <LOCATION> ABC </LOCATION>
    </ITEM>
    <ITEM>
    <NAME> Item2 </NAME>
    <PRICE> 600 </PRICE>
    <LOCATION> XYZ</LOCATION>
    </ITEM>
    <ITEM>
    <NAME> Item3 </NAME>
    <PRICE> 700 </PRICE>
    <LOCATION> DEF</LOCATION>
    </ITEM>
    <ITEM>
    <NAME> Item4 </NAME>
    <PRICE> 900 </PRICE>
    <LOCATION> QWE</LOCATION>
    </ITEM>
    </ITEMLIST>



    ------------------------------------------------------------------------------------------------------
    XSL file ( name myxsl.xsl)
    ------------------------------------------------------------------------------------------------------
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml" version="1.0" doctype-public="-//W3C//DTD
    XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

    <xsl:template match="/">
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Data Sheet</title>
    <link rel="stylesheet" type="text/css" href="mycss.css" />
    </head>
    <body>
    <table>
    <tr>
    <th>A</th>
    <th>B</th>
    </tr>
    <tr class="row0">
    <td>1</td>
    <td>2</td>
    </tr>
    <tr class="row1">
    <td>3</td>
    <td>4</td>
    </tr>
    </table>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="ITEMLIST">
    <table>
    <tr>
    <th>Name</th>
    <th>Price</th>
    <th>Location</th>
    </tr>
    <xsl:for-each select="ITEM">
    <tr class="row1">
    <td><xsl:value-of select="NAME" /></td>
    <td><xsl:value-of select="PRICE" /></td>
    <td><xsl:value-of select="LOCATION" /></td>
    </tr>
    </xsl:for-each>
    </table>
    </xsl:template>

    </xsl:stylesheet>




    ------------------------------------------------------------------------------------------------------
    CSS file ( name mycss.css)
    ------------------------------------------------------------------------------------------------------

    html body {
    line-height:1.55em;
    font-family:"Lucida Grande", verdana, lucida, helvetica, sans-serif;

    margin:0;
    padding:0;
    font-size:x-small;
    font-size:small;
    }


    table
    {
    display: table;
    border-collapse:collapse;
    empty-cells:show;
    border-top:1px solid #ccc;
    border-right:1px solid #ccc;
    border-left:1px solid #ccc;
    border-bottom:1px solid #ccc;
    }


    tr {
    display: table-row;
    }

    ..row0 {
    background-color:yellow;
    color:#1559B3;
    }
    ..row1 {
    background-color:red;
    color:#1559B3;
    }

    td {
    display: table-cell;
    border-top:1px solid #ccc;
    border-right:1px solid #ccc;
    border-left:1px solid #ccc;
    border-bottom:1px solid #ccc;
    }

    th {
    display: table-cell;
    border-top:1px solid #ccc;
    border-right:1px solid #ccc;
    border-left:1px solid #ccc;
    border-bottom:1px solid #ccc;
    font-weight: 700;
    background-color:#99cccc;

    }

    If you have any idea about this issue, please do reply....
    Pradeep, Jan 16, 2008
    #1
    1. Advertising

  2. Pradeep

    Pavel Lepin Guest

    Pradeep <> wrote in
    <>:
    > I am facing one problem , that ITEM rows are not displayed
    > in proper color (RED) as mentioned in css file for
    > .row1...... Same thing works well if the table is created
    > in <xsl:template match="/"> but doesn't work for table
    > created in <xsl:template match="ITEMLIST">.
    >
    > <?xml version="1.0"?>
    > <xsl:template match="/">
    > <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    > <head>
    > <title>Data Sheet</title>
    > <link rel="stylesheet" type="text/css" href="mycss.css" />
    > </head>
    > <body>
    > <table>


    Guess what? This table element is XHTML namespace...

    > <xsl:template match="ITEMLIST">
    > <table>


    ....and this one isn't. If you used a standalone processor to
    debug your transformation, the problem would've been
    immediately obvious.

    --
    ....also, I submit that we all must honourably commit seppuku
    right now rather than serve the Dark Side by producing the
    HTML 5 spec.
    Pavel Lepin, Jan 16, 2008
    #2
    1. Advertising

  3. Pradeep

    Pradeep Guest

    On Jan 16, 1:24 pm, Pavel Lepin <> wrote:
    > Pradeep <> wrote in
    > <>:
    >
    > > I am facing one problem , that ITEM rows are not displayed
    > > in proper color (RED) as mentioned in css file for
    > > .row1...... Same thing works well if the table is created
    > > in <xsl:template match="/"> but doesn't work for table
    > > created in <xsl:template match="ITEMLIST">.

    >
    > > <?xml version="1.0"?>
    > > <xsl:template match="/">
    > > <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    > > <head>
    > > <title>Data Sheet</title>
    > > <link rel="stylesheet" type="text/css" href="mycss.css" />
    > > </head>
    > > <body>
    > > <table>

    >
    > Guess what? This table element is XHTML namespace...
    >
    > > <xsl:template match="ITEMLIST">
    > > <table>

    >
    > ...and this one isn't. If you used a standalone processor to
    > debug your transformation, the problem would've been
    > immediately obvious.
    >
    > --
    > ...also, I submit that we all must honourably commit seppuku
    > right now rather than serve the Dark Side by producing the
    > HTML 5 spec.



    I am new to this XML world, can you pleas tell me how to debug
    transformation
    Pradeep, Jan 16, 2008
    #3
  4. Pradeep

    Pavel Lepin Guest

    Pradeep <> wrote in
    <>:
    > On Jan 16, 1:24 pm, Pavel Lepin <>
    > wrote:
    >> Pradeep <> wrote:
    >> > I am facing one problem , that ITEM rows are not
    >> > displayed in proper color (RED) as mentioned in css
    >> > file for .row1...... Same thing works well if the table
    >> > is created in <xsl:template match="/"> but doesn't work
    >> > for table created in <xsl:template match="ITEMLIST">.

    >>
    >> > <?xml version="1.0"?>
    >> > <xsl:template match="/">
    >> > <html lang="en"
    >> > xmlns="http://www.w3.org/1999/xhtml"> <head>
    >> > <title>Data Sheet</title>
    >> > <link rel="stylesheet" type="text/css" href="mycss.css"
    >> > />
    >> > </head>
    >> > <body>
    >> > <table>

    >>
    >> Guess what? This table element is XHTML namespace...


    "*in* XHTML namespace", of course.

    >>
    >> > <xsl:template match="ITEMLIST">
    >> > <table>

    >>
    >> ...and this one isn't. If you used a standalone processor
    >> to debug your transformation, the problem would've been
    >> immediately obvious.

    >
    > I am new to this XML world, can you pleas tell me how to
    > debug transformation


    You get a standalone XSLT processor somewhere, and stuff
    your document and your transformation into it. Then look at
    the output. Add <xsl:message>s as needed.

    Two standalone XSLT processors I normally recommend are
    xsltproc and Saxon. Saxon, because it's a conformant XSLT2
    implementation, as well as XQuery processor; xsltproc,
    because it comes with the libxslt package and therefore is
    pretty much ubiquitous.

    --
    ....also, I submit that we all must honourably commit seppuku
    right now rather than serve the Dark Side by producing the
    HTML 5 spec.
    Pavel Lepin, Jan 16, 2008
    #4
  5. Pavel Lepin wrote:
    > Two standalone XSLT processors I normally recommend are
    > xsltproc and Saxon. Saxon, because it's a conformant XSLT2
    > implementation, as well as XQuery processor; xsltproc,
    > because it comes with the libxslt package and therefore is
    > pretty much ubiquitous.


    I'd add Apache Xalan to that list, especially if the interactive
    stylesheet debugger (an Eclipse plugin) still exists and still works.

    Yes, you debug stylesheets by comparing their output with what you
    expect, adding xsl:message or other telltales to help probe what's going
    on as needed. See also my article on DeveloperWorks
    (http://www.ibm.com/xml) on using XSLT to "style stylesheets" to add
    debugging information automagically.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Jan 16, 2008
    #5
  6. Pradeep

    Pavel Lepin Guest

    Joseph Kesselman <> wrote in
    <478e191d$1@kcnews01>:
    > Pavel Lepin wrote:
    >> Two standalone XSLT processors I normally recommend are
    >> xsltproc and Saxon. Saxon, because it's a conformant
    >> XSLT2 implementation, as well as XQuery processor;
    >> xsltproc, because it comes with the libxslt package and
    >> therefore is pretty much ubiquitous.

    >
    > I'd add Apache Xalan to that list, especially if the
    > interactive stylesheet debugger (an Eclipse plugin) still
    > exists and still works.


    I don't have anything against Xalan, or recommending Xalan
    to others, honest. :) In fact, Xalan's CLI processor is
    another one I use regularly. I just feel that between
    libxslt's ubiquity and Saxon's stark raving XSLT2-ishness
    they already cover most bases a neophyte might find useful.
    And if they don't there's always Google.

    Of course, there's a bit of personal bias there - if I were
    using Xalan instead of libxslt in my work, I would likely
    be recommending it by default.

    --
    ....also, I submit that we all must honourably commit seppuku
    right now rather than serve the Dark Side by producing the
    HTML 5 spec.
    Pavel Lepin, Jan 16, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 5tein
    Replies:
    1
    Views:
    454
    Patrick TJ McPhee
    Apr 30, 2004
  2. Replies:
    1
    Views:
    3,572
    A. Bolmarcich
    May 27, 2005
  3. schaf
    Replies:
    3
    Views:
    1,296
    schaf
    Sep 16, 2005
  4. Kourosh
    Replies:
    6
    Views:
    835
    Peter Flynn
    May 17, 2006
  5. Pradeep

    XML, XSL, CSS attribute issue

    Pradeep, Jan 16, 2008, in forum: HTML
    Replies:
    2
    Views:
    431
    Harlan Messinger
    Jan 16, 2008
Loading...

Share This Page