Linking to a separate CSS in XSL

Discussion in 'XML' started by Jyrki Keisala, Dec 15, 2003.

  1. I am a newbie in using XSL to transform my XML documents into HTML.
    Let's say I have an XML like this:

    foo.xml:
    --------

    <?xml version="1.0" ?>
    <?xml:stylesheet type="text/xsl" href="foo.xsl"?>

    <root>

    <element>
    <name>Brian</name>
    <email></email>
    </element>

    <element>
    <name>Jeff</name>
    <email></email>
    </element>
    ..
    ..
    </root>


    Now I'd like to convert my XML data into a HTML table, by using the XSL.
    The basic trick I can handle:


    foo.xsl:
    --------

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">

    <html>

    <head>
    <title>My contacts</title>
    </head>

    <body>
    <h1>All of my contacts in one huge table</h1>
    <p>
    An ordinary paragraph of text.
    </p>
    <table border="1">
    <tr>
    <td>Name</td>
    <td>E-mail address</td>
    </tr>
    <xsl:for-each select="root/element">
    <tr>
    <td><xsl:value-of select="name"/></td>
    <td><xsl:value-of select="email"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>

    </html>

    </xsl:template>
    </xsl:stylesheet>


    Question: what if I want to format the HTML table created by a separate
    CSS file, say "my_style.css"? That file includes the normal CSS style
    definitions like


    my_style.css:
    -------------

    p,table,li,h1,h2,h3
    {
    font-family: verdana, arial, 'sans serif';
    }

    p, h1, h2, h3, table, li, hr
    {
    margin-left: 10pt;
    }

    p,li,th,td
    {
    font-size: 75%;
    }


    Where in my XSL can I put the link to a separate CSS, to take all of that
    style formatting into use in my XSL-generated HTML table? Or is there
    some other mechanism for that in XSL?
     
    Jyrki Keisala, Dec 15, 2003
    #1
    1. Advertising

  2. "Jyrki Keisala" <> wrote in message
    news:Xns9452838F4E0ECzoltanjippiifi@131.228.6.99...
    [...]
    > Now I'd like to convert my XML data into a HTML table, by using the XSL.
    > The basic trick I can handle:
    >
    >
    > foo.xsl:
    > --------
    >
    > <?xml version="1.0"?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    > <xsl:template match="/">
    >
    > <html>
    >
    > <head>
    > <title>My contacts</title>


    Add <link rel="stylesheet" type="text/css" href="my_style.css"/> here.


    > </head>


    <body/>

    > </html>
    >
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >
    > Question: what if I want to format the HTML table created by a separate
    > CSS file, say "my_style.css"? That file includes the normal CSS style
    > definitions like


    See above. The idea is that the output HTML document refers to the
    stylesheet.

    Groetjes,
    Maarten Wiltink
     
    Maarten Wiltink, Dec 15, 2003
    #2
    1. Advertising

  3. "Maarten Wiltink" <> wrote in
    news:3fdd99fa$0$211$4all.nl:

    > "Jyrki Keisala" <> wrote in message
    > news:Xns9452838F4E0ECzoltanjippiifi@131.228.6.99...
    > [...]
    >> Now I'd like to convert my XML data into a HTML table, by using the
    >> XSL. The basic trick I can handle:
    >>
    >>
    >> foo.xsl:
    >> --------
    >>
    >> <?xml version="1.0"?>
    >> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    >> <xsl:template match="/">
    >>
    >> <html>
    >>
    >> <head>
    >> <title>My contacts</title>

    >
    > Add <link rel="stylesheet" type="text/css" href="my_style.css"/> here.
    >
    >
    >> </head>

    >
    > <body/>
    >
    >> </html>
    >>
    >> </xsl:template>
    >> </xsl:stylesheet>
    >>
    >>
    >> Question: what if I want to format the HTML table created by a
    >> separate CSS file, say "my_style.css"? That file includes the normal
    >> CSS style definitions like

    >
    > See above. The idea is that the output HTML document refers to the
    > stylesheet.
    >
    > Groetjes,
    > Maarten Wiltink
    >
    >


    Are you actually using that trick? I tried to do just that, but got an
    error message from the IE.
     
    Jyrki Keisala, Dec 15, 2003
    #3
  4. Jyrki Keisala wrote:

    > I am a newbie in using XSL to transform my XML documents into HTML.


    > foo.xsl:
    > --------
    >
    > <?xml version="1.0"?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">


    Are you sure you want that namespace http://www.w3.org/TR/WD-xsl?
    The correct namespace for XSLT 1.0 is http://www.w3.org/1999/XSL/Transform.
    Only older IE versions should support http://www.w3.org/TR/WD-xsl but
    the language defined by that namespace is different from XSLT 1.0.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 15, 2003
    #4
  5. Jyrki Keisala wrote:

    > "Maarten Wiltink" <> wrote in
    > news:3fdd99fa$0$211$4all.nl:
    >
    >
    >>"Jyrki Keisala" <> wrote in message
    >>news:Xns9452838F4E0ECzoltanjippiifi@131.228.6.99...
    >>[...]
    >>
    >>>Now I'd like to convert my XML data into a HTML table, by using the
    >>>XSL. The basic trick I can handle:
    >>>
    >>>
    >>>foo.xsl:
    >>>--------
    >>>
    >>><?xml version="1.0"?>
    >>><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    >>><xsl:template match="/">
    >>>
    >>><html>
    >>>
    >>><head>
    >>><title>My contacts</title>

    >>
    >>Add <link rel="stylesheet" type="text/css" href="my_style.css"/> here.
    >>
    >>
    >>
    >>></head>

    >>
    >><body/>
    >>
    >>></html>
    >>>
    >>></xsl:template>
    >>></xsl:stylesheet>
    >>>
    >>>
    >>>Question: what if I want to format the HTML table created by a
    >>>separate CSS file, say "my_style.css"? That file includes the normal
    >>>CSS style definitions like

    >>
    >>See above. The idea is that the output HTML document refers to the
    >>stylesheet.
    >>
    >>Groetjes,
    >>Maarten Wiltink
    >>
    >>

    >
    >
    > Are you actually using that trick? I tried to do just that, but got an
    > error message from the IE.


    Which error message?
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 15, 2003
    #5
    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. EvgueniB
    Replies:
    1
    Views:
    655
    Anthony Borla
    Dec 15, 2003
  2. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  3. Frank Fredstone
    Replies:
    1
    Views:
    460
    Jean-Francois Briere
    Jun 27, 2006
  4. John Hosking
    Replies:
    0
    Views:
    414
    John Hosking
    Jan 26, 2009
  5. Andy Dingley
    Replies:
    0
    Views:
    430
    Andy Dingley
    Jan 26, 2009
Loading...

Share This Page