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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl javascript firefox 1

Status
Not open for further replies.

JustinEzequiel

Programmer
Jul 30, 2001
1,192
PH
The following works just fine in IE but not in FireFox.
What am I doing wrong?
The FireFox page-loading indicator just keeps going but the page does not load completely.
If I add a document.close(), the indicator stops but I do not get the rest of the output.
FireFox output stops at the emphasized "This will work".

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method='html' version='1.0' encoding='UTF-8'/>

  <xsl:variable name="root" select="/files/@path"/>
  
  <xsl:template match="/">
    <html>
    <head>
    <title>Directory listing for <xsl:value-of select="$root" /></title>
    </head>
    <body>
        <script type="text/javascript">
          document.write ("&lt;em&gt;This will work&lt;\/em&gt;")
        </script>
        <hr />

        <xsl:apply-templates select="files"/>
        
        <hr />
    </body>
    </html>
  </xsl:template>
  
  <xsl:template match="files">
    <table border="1" cellspacing="3" cellpadding="3" style="border-collapse:collapse">
      <tr>
        <th>Name</th>
        <th>Size</th>
        <th>Modified</th>
      </tr>

    <xsl:for-each select="file">
    <xsl:sort select="@name"/>
      <tr>
        <td><xsl:value-of select="@name" /></td>
        <td align="right"><xsl:value-of select="format-number(@size, '#,###')" /></td>
        <td><xsl:value-of select="@date" /></td>
      </tr>
    </xsl:for-each>

    </table>
  </xsl:template>

</xsl:stylesheet>

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ONLINE.xsl"?>
<files path="/springer/mik60007/trunk/graphics/output/ONLINE/">
<file date="2007-02-12 13:57:16" name="s14344-006-0007-4flb1.gif" size="1748517485" />
<file date="2007-02-12 13:57:16" name="s14344-006-0007-4flb2.gif" size="15407" />
<file date="2007-02-12 13:57:16" name="s14344-006-0007-4flb3.gif" size="15366" />
</files>
 
[1] For intersperse use of document.write within some static html tagging, it would normally require judicious use of document.open() and document.close() to avoid hanging in general in moz/ff/nn or at times ie. With that idea, we would aniticipate something like this.
[tt]
<xsl:template match="/">
<script type="text/javascript">
document.open();
</script>
<html>
<head>
<!-- etc etc -->
</body>
</html>
<script type="text/javascript">
document.close();
</script>
</xsl:template>
[/tt]
(The exact place can vary a bit to everybody's taste with the same result.) In this case, the table does show but on moz/ff/nn it still hang... This residue "hanging" is specifically related to xml-xslt rendering and is recognized as a "bug":
ref
[2] The proper remedy is to use moz/ff/nn specific script on those particular places. Like this.
[tt]
<body>
<xsl:if test="system-property('xsl:vendor')='Transformiix'">
<!-- moz specific rendering -->
<em>This will work</em>
</xsl:if>
<xsl:if test="system-property('xsl:vendor')='Microsoft'">
<!-- ie specific rendering -->
<!-- But in this case, not using document.write is complete acceptable and better conceived. I just keep it as such for illustration. -->
<script type="text/javascript">
document.write ("&lt;em&gt;This will work&lt;\/em&gt;")
</script>
</xsl:if>
<hr />
<xsl:apply-templates select="files"/>
<hr />
</body>
[/tt]
 
Thanks tsuji!

The example was contrived (i.e., simplified).

My actual script had a for-loop and other stuff to calculate HREFs.
Was eventually able to calculate/generate the HREFs via only XSLT.

However, later, I'm hoping to add scripts to allow users to sort the table columns by clicking on the column headers.
Will ask here if I encounter problems.

BTW, thanks for the URL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top