Forum Moderators: open
Here is the name of the css file and the file,
my_bookstyle.css:
body { font-size: 12pt; font-family: Arial, Helvetica, sans-serif;}
A:link { color: #000000; text-decoration: underline;}
A:visited { color: #336699; text-decoration: underline;}
A:hover { color: #CC9900; text-decoration: underline;}
table {width: 60%; }
tr {background:beige;}
Here is the table row to apply the style.
<xsl:element name="tr ><xsl:element
name="td">TITLE</xsl:element>
<xsl:element name="td"><xsl:value-of select="parent::item/title"
/></xsl:element></xsl:element>
Would someone please tell me how to do this if it is possible.
First of all, in your CSS, add another selector with a class for your TR element that will be colored differently. I added a selector & class called "tr.highlight" and gave it a background-color style of red.
Next, you will add an attribute part to your XSL specifying the class as the attribute and it will work.
my_bookstyle.css:
body { font-size: 12pt; font-family: Arial, Helvetica, sans-serif;}
A:link { color: #000000; text-decoration: underline;}
A:visited { color: #336699; text-decoration: underline;}
A:hover { color: #CC9900; text-decoration: underline;}
table {width: 60%; }
tr {background:beige;}
tr.highlight {background-color:red;}
Your XSL will be:
<xsl:element name="tr >
<xsl:attribute name="class">
<xsl:value-of select="@class" />
</xsl:attribute>
<xsl:element
name="td">TITLE</xsl:element>
<xsl:element name="td"><xsl:value-of select="parent::item/title"
/></xsl:element></xsl:element>
Since you did not add your actual XML, I cannot give you the correct XPATH, but I am sure you will figure it out. Once you have the correct XPATH syntax, it will work.
I tried this on my PC and it worked. I hope this helps.
Bruce C
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<html>
<link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
<body>
<table>
<!-- The is the Sortation Option section. -->
<tr><td align="left"> Books Sorted by Author </td><td align="left"> Sort By: </td><td><a href="My_Books_title.xml" > Title </a>
</td><td> or </td><td><a href="My_Books_main.xml"> Subject </a></td></tr>
</table>
<xsl:for-each select="data/item/author">
<xsl:sort select="normalize-space(author)" />
<table>
<tr bgcolor="#999920" width="30%"><td width="30%"><xsl:value-of select="author" /> <xsl:value-of select="."/> </td>
</tr>
</table>
<xsl:call-template name="aTable">
<xsl:with-param name="aAuthor" />
</xsl:call-template>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="aTable" match="/item">
<xsl:element name="table">
<!-- THIS WORKS<xsl:element name="tr"><xsl:attribute name="bgcolor">beige</xsl:attribute> -->
<!-- THIS WORKS<tr class="highlight"><td>TITLE</td><td><xsl:value-of select="parent::item/title" /></td></tr> -->
<xsl:element name="tr"><xsl:attribute name="class">highlight</xsl:attribute>
<xsl:element name="td"> TITLE </xsl:element>
<xsl:element name="td"><xsl:value-of select="parent::item/title" /> </xsl:element>
</xsl:element>
<xsl:for-each select="parent::item/author">
<xsl:element name="tr"><xsl:element name="td">AUTHOR/s</xsl:element><xsl:element name="td"><xsl:value-of select="." /> </xsl:element> </xsl:element>
</xsl:for-each>
<xsl:element name="tr"><xsl:element name="td">EDITION</xsl:element><xsl:element name="td"> <xsl:value-of select="parent::item/edition" /> </xsl:element></xsl:element>
<xsl:element name="tr"><xsl:element name="td">PUBLISHER</xsl:element><xsl:element name="td"> <xsl:value-of select="parent::item/publisher" /> </xsl:element></xsl:element>
<xsl:element name="tr"><xsl:element name="td">ISBN</xsl:element><xsl:element name="td"><xsl:value-of
select="parent::item/isbn" /></xsl:element></xsl:element>
<xsl:element name="tr"><xsl:element name="td">LCCN</xsl:element><xsl:element name="td"><xsl:value-of
select="parent::item/lccn" /></xsl:element></xsl:element>
<xsl:element name="tr"><xsl:element name="td">PRICE</xsl:element><xsl:element name="td"><xsl:value-of select="parent::item/price" /></xsl:element></xsl:element>
<xsl:element name="tr"><xsl:element name="td">SUBJECT</xsl:element><xsl:element name="td"><xsl:element name="p">
<xsl:value-of select="parent::item/subject" /></xsl:element></xsl:element></xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
HERE IS THE my_bookstyle.css file.
body { font-size: 12pt; font-family: Arial, Helvetica, sans-serif;}
A:link { color: #000000; text-decoration: underline;}
A:visited { color: #336699; text-decoration: underline;}
A:hover { color: #CC9900; text-decoration: underline;}
table {width: 60%; }
.highlight {background-color:beige; }
<!-- THIS METHOD ALSO WORKS, just remove the
unnecessary comment make and see the difference.
<style> -->
<!-- .highlight { background-color:#CC9900; } -->
<!-- </style> -->