Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad XSL Transformation in Firefox 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
When I open the following xml file in Internet Explorer 6 everything is formatted neatly into a table as desired. However, when I view the same xml file in Firefox the header_record and table all appear on one line appropriately coloured by the style set at the top of the stylesheet. Does anyone know the reason for this?

Here is my source code:
example.xsl
Code:
<?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:fo="[URL unfurl="true"]http://www.w3.org/1999/XSL/Format">[/URL]
  <xsl:template match="/">
   <html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
    <head>
     <style type="text/css">
      h2
      {
       background-color: #000000;
       color: #FFFFCC;
       text-align: center;
      }

      h3
      {
       background: #FFFFCC;
       text-align: center;
      }

      h4
      {
       background: #FFCC99;
       text-align: center;
      }

      table
      {
       border-color: #000000 #000000 #000000 #000000;
       border-spacing: 2;
       border-width: 2;
       padding: 2;
      }

      td.heading
      {
       background: #0000CC;
       color: #FFFFFF;
       font-weight: bold;
      }

      td.total
      {
       font-weight: bold;				
      }
				
      td
      {
       background: #CCCCFF;
      }
     </style>
     <title>Network Data File</title>
    </head>
    <body>
      <h2>Network Data File</h2>
      <xsl:apply-templates select="network_data_file/header_record"/>
    </body>
   </html>
  </xsl:template>
  <xsl:template match="header_record">
   <h3>Header Record</h3>
   <table border="1">
    <tr>
     <td class="heading"> Network Name </td>
     <td class="heading"> State Name </td>
    </tr>
    <tr>
     <td><xsl:value-of select="netName"/></td>
     <td><xsl:value-of select="stateName"/></td>
    </tr>
   </table>
  </xsl:template>
 </xsl:stylesheet>
example.xml
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="example.xsl" ?>
<network_data_file xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="network_data_file.xsd">
 <header_record>
  <netName>Example</netName>
  <stateName>On</stateName>
 </header_record>
</network_data_file>

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
>When I open the following xml file in Internet Explorer 6 everything is formatted neatly into a table as desired. However, when I view the same xml file in Firefox the header_record and table all appear on one line appropriately coloured by the style set at the top of the stylesheet. Does anyone know the reason for this?

The reason is that the vocabulary is unknown to the namespace the parser is trying to interprete when it reads the template apart.

To illustrate the mechanism, I can show you how to make cases out of your example.xls. Then we may understand the thing better.

[1] The realization of example.xls which works in ie and fails in moz/ff. --- This you have shown us.

[2] The realization of example.xls which works in moz/ff and fails in ie.
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl=" xmlns:fo=" [red]xmlns:html="[/red]>
<xsl:template match="/">
<html xmlns=" <head>
<style type="text/css">
h2{background-color: #000000;color: #FFFFCC;text-align: center;}
h3{background: #FFFFCC;text-align:center;}
h4{background: #FFCC99;text-align: center;}
table{border-color: #000000 #000000 #000000 #000000;border-spacing: 2; border-width: 2;padding: 2;}
td.heading{background: #0000CC;color: #FFFFFF;font-weight: bold;}
td.total{font-weight: bold;}
td{background: #CCCCFF;}
</style>
<title>Network Data File</title>
</head>
<body>
<h2>Network Data File</h2>
<h3>Header Record</h3>
<xsl:apply-templates select="network_data_file/header_record" />
</body>
</html>
</xsl:template>

<xsl:template match="network_data_file/header_record">
<[red]html:[/red]table border="1">
<html:tr>
<html:td class="heading"> Network Name </html:td>
<html:td class="heading"> State Name </html:td>
</html:tr>
<html:tr>
<html:td><xsl:value-of select="netName" /></html:td>
<html:td><xsl:value-of select="stateName" /></html:td>
</html:tr>
</[red]html:[/red]table>
</xsl:template>
</xsl:stylesheet>
[/tt]
[3] The realization of example.xls which works both in moz/ff and in ie.
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl=" xmlns:fo=" [red]xmlns="[/red]>
<xsl:template match="/">
<!-- is not really matter
<html xmlns=" -->
<html>
<head>
<style type="text/css">
h2{background-color: #000000;color: #FFFFCC;text-align: center;}
h3{background: #FFFFCC;text-align:center;}
h4{background: #FFCC99;text-align: center;}
table{border-color: #000000 #000000 #000000 #000000;border-spacing: 2; border-width: 2;padding: 2;}
td.heading{background: #0000CC;color: #FFFFFF;font-weight: bold;}
td.total{font-weight: bold;}
td{background: #CCCCFF;}
</style>
<title>Network Data File</title>
</head>
<body>
<h2>Network Data File</h2>
<h3>Header Record</h3>
<xsl:apply-templates select="network_data_file/header_record" />
</body>
</html>
</xsl:template>

<xsl:template match="network_data_file/header_record">
<table border="1">
<tr>
<td class="heading"> Network Name </td>
<td class="heading"> State Name </td>
</tr>
<tr>
<td><xsl:value-of select="netName" /></td>
<td><xsl:value-of select="stateName" /></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
[/tt]
With these variations, it would articulate better the problem involved.
 
That's fantastic tsuji. I now have it working in IE & FF using your 3rd example!

In your 2nd example, it is my understanding that you are explicitly declaring and using an html namespace, so why is it that IE doesn't recognise this?

In your 3rd example, am I correct in assuming that because you have not given a specific prefix in the following line this then acts as the default namespace for any tags that do not include a prefix? Thus, the html tags I've included do not have a prefix and so are assumed to be associated with the default xhtml namespace?
Code:
xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL]

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
When I typed example.xls, I sure meant example.xsl.

As to the reason why [2] failing ie, I can only say the thing to me is still surrounded by mystery in the sense that I cannot say for sure what goes wrong in the implementation. It is unfortunate as a rule in xsl the innovation and standardization does not match over time, sometimes one leads, some other times one trails. And am not fluent enough to disperse all cloud.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top