rookwood Posted December 15, 2005 Share Posted December 15, 2005 Hi, I've built a stylesheet that displays the content of my xml message as an Html table. It all works fine as long as the element has non-blank space content. However, when elements contain a blankspace or no content the table renders incorrectly. i.e the individual <td></td> elements display with no table border.I've been trying to insert entities in the empty cells but can't seem to get that to work.sample msg:<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="instrument_table.xsl" ?><Instruments><changed> <ID_BB_UNIQUE>ABCDEFG</ID_BB_UNIQUE> <ID_SEDOL1>S02548</ID_SEDOL1> <ID_SEDOL2> </ID_SEDOL2> <ID_SEDOL3></ID_SEDOL3> <TICKER>BA</TICKER> </changed><changed> <ID_BB_UNIQUE>PQRSTUV</ID_BB_UNIQUE> <ID_SEDOL1>B0JYD4</ID_SEDOL1> <ID_SEDOL2>B095JTY</ID_SEDOL2> <ID_SEDOL3></ID_SEDOL3> <TICKER>BA</TICKER></changed></Instruments>Stylesheet:<xsl:output method="xml" indent="yes" media-type="text/xml"/><xsl:template match="/Instruments"><html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"><head><title>Instrument changes</title></head><body><font face="arial"><table> <tr> <td> <p>Instrument List</p> </td> </tr><tr><td> <table border='1' cellpadding='5' align='Left'> <tr bgcolor="#cccccc"> <th>BLOOMBERG ID</th> <th>SEDOL1</th> <th>SEDOL2</th> <th>SEDOL3</th> <th>TICKER</th> </tr> <xsl:for-each select="changed"> <tr> <td><xsl:value-of select="ID_BB_UNIQUE"/></td> <td><xsl:value-of select="ID_SEDOL1"/></td> <td><xsl:value-of select="ID_SEDOL2"/></td> <td><xsl:value-of select="ID_SEDOL3"/></td> <td><xsl:value-of select="TICKER"/></td> </tr> </xsl:for-each> </table></td></tr></table></font></body></html></xsl:template></xsl:stylesheet>Anyone have a bright idea?CheersG Link to comment Share on other sites More sharing options...
boen_robot Posted December 15, 2005 Share Posted December 15, 2005 Well, at first I must say it's like you have some errors in your code. I kind of solved your problem, but the solution I found makes some other rather weird errors. Previewing the XML in IE resulted in placing a "B" instead of a space. In FireFox however, everything was fine. It's kind of odd, scince IE is known to have a full XML support.The partial solution to your problem was a DTD in which the entities(and in the process: all other elements) are specified.instrument_table.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Instruments [ <!ELEMENT Instruments ANY> <!ELEMENT changed ANY> <!ELEMENT ID_BB_UNIQUE ANY> <!ELEMENT ID_SEDOL1 ANY> <!ELEMENT ID_SEDOL2 ANY> <!ELEMENT ID_SEDOL3 ANY> <!ELEMENT TICKER ANY> <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY yen "¥"> <!ENTITY euro "€">]><?xml-stylesheet type="text/xsl" href="instrument_table.xsl" ?><Instruments><changed><ID_BB_UNIQUE>ABCDEFG</ID_BB_UNIQUE><ID_SEDOL1>S02548</ID_SEDOL1><ID_SEDOL2> </ID_SEDOL2><ID_SEDOL3> </ID_SEDOL3><TICKER>BA</TICKER></changed><changed><ID_BB_UNIQUE>PQRSTUV</ID_BB_UNIQUE><ID_SEDOL1>B0JYD4</ID_SEDOL1><ID_SEDOL2>B095JTY</ID_SEDOL2><ID_SEDOL3> </ID_SEDOL3><TICKER>BA</TICKER></changed></Instruments> instrument_table.xsl <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ELEMENT Instruments ANY> <!ELEMENT changed ANY> <!ELEMENT ID_BB_UNIQUE ANY> <!ELEMENT ID_SEDOL1 ANY> <!ELEMENT ID_SEDOL2 ANY> <!ELEMENT ID_SEDOL3 ANY> <!ELEMENT TICKER ANY> <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY yen "¥"> <!ENTITY euro "€">]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/><xsl:template match="/Instruments"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Instrument changes</title></head><body><font face="arial"><table><tr><td><p>Instrument List</p></td></tr><tr><td><table border='1' cellpadding='5' align='Left'><tr bgcolor="#cccccc"><th>BLOOMBERG ID</th><th>SEDOL1</th><th>SEDOL2</th><th>SEDOL3</th><th>TICKER</th></tr><xsl:for-each select="changed"><tr><td><xsl:value-of select="ID_BB_UNIQUE"/></td><td><xsl:value-of select="ID_SEDOL1"/></td><td><xsl:value-of select="ID_SEDOL2"/></td><td><xsl:value-of select="ID_SEDOL3"/></td><td><xsl:value-of select="TICKER"/></td></tr></xsl:for-each></table></td></tr></table></font></body></html></xsl:template></xsl:stylesheet> Link to comment Share on other sites More sharing options...
rookwood Posted December 16, 2005 Author Share Posted December 16, 2005 Thanks for taking the time to look at this; looks like i can learn some good stuff from your approach. I actually managed to kludge it yesterday using xsl:if to test for absence of data in the element and inserting " <br> " where that was the case. It was a last straw approach and bizarrely worked fine. Whilst trawling the web I came across several examples of tables built from xml and stylesheet which all sufferred the same rendering problem in my versions of Explorer (v6.02). Annoying since Outlook shares the HTML/xml rendering engine and the end game of my work is generating HTML e-mail for my client from xml input.CheersG Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now