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