Linking to a separate CSS in XSL

J

Jyrki Keisala

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 protected]</email>
</element>

<element>
<name>Jeff</name>
<email>[email protected]</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?
 
M

Maarten Wiltink

[...]
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>

</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
 
J

Jyrki Keisala

[...]
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>

</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.
 
M

Martin Honnen

Jyrki said:
[...]
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.



</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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top