Javascript Error in xsl file from report

Bug reports.
SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Javascript Error in xsl file from report

Post by SeanP » Tue Apr 12, 2011 10:25 pm

Hi,

I am attempting to take the xsl file and xml file and build an html page for an application I am building. However when I do the transform function and then try to bind the HTML string to the webbrowser object I am using, i get an error and the error can be traced to the javascript in the style. See the following text and check for errors by putting it in a new html file. (i am using firefox and checking the error console). The error i get is "missing ) after for-loop control.

The error is coming from this code from what I can tell....

Code: Select all

function switchVisibility(firstclassName, excludeClassname)
			{
				var tr = document.getElementsByTagName('tr');
				for(var i=0;i<tr.length;i++)
				{
					if(tr[i].className.search(firstclassName + ' invisible')>=0 && (tr[i].className.search(excludeClassname)<0 || excludeClassname=="")) 
						tr[i].className = tr[i].className.replace(firstclassName + ' invisible', firstclassName);
					else if(tr[i].className.search(firstclassName)>=0 && (tr[i].className.search(excludeClassname)<0 || excludeClassname==""))
					  	tr[i].className = tr[i].className.replace(firstclassName, firstclassName + ' invisible');
				}
			}


Thanks,
Sean


Sorry for the ugliness of the code, its how it was built in VS2008.

Code: Select all

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="message">

    <!--<xsl:choose>
          <xsl:when test ="./Result/State = $TRUE">
          <xsl:variable name="Path" select="./General/TestcaseName"/>
            <td width="32%" bgcolor="#00FF00"><a href="{./General/TestcaseName/@href}"><xsl:value-of select ="./General/TestcaseName"/></a></td>
            <td width="68%" bgcolor="#00FF00"><xsl:value-of select ="./Result/State"/></td>
          </xsl:when>
          <xsl:otherwise >
            <td width="32%" bgcolor="#FF0000"><a href="{./General/TestcaseName/@href}"><xsl:value-of select ="./General/TestcaseName"/></a></td>
            <td width="68%" bgcolor="#FF0000"><xsl:value-of select ="./Result/State"/></td>
          </xsl:otherwise>
        </xsl:choose>
		-->
    <xsl:choose>
      <xsl:when test ="@level = 'WARN'">
        <tr class="warn {./@category}Warn" style="{@style}">
		  <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:when>
      <xsl:when test ="@level = 'ERROR'">
        <tr class="error {./@category}Error" style="{@style}">
		  <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:when>
      <xsl:when test ="@level = 'DEBUG'">
        <tr class="debug" style="{@style}">
          <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:when>
      <xsl:when test ="@level = 'SUCCESS'">
        <tr class="success" style="{@style}">
          <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:when
		>
      <xsl:when test ="@level = 'FAILURE'">
        <tr class="failure" style="{@style}">
          <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:when>
      <xsl:otherwise>
        <tr class="info {./@category}Info" style="{@style}">
          <td>
            <xsl:value-of select ="./@time"/>
          </td>
          <td>
            <xsl:value-of select ="./@level"/>
          </td>
          <td>
            <xsl:value-of select ="./@category"/>
          </td>
          <td>
           <xsl:copy-of select ="child::node()"/>
          </td>
        </tr>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

  <xsl:template match="/log">
    <html>
      <head>
        <title>
          <xsl:value-of select ="/log/@title"/>
        </title>
        <link rel="stylesheet" type="text/css" href="http://www.ranorex.com/fileadmin/templates/NewDesign/css/style.css" />
        <style type="text/css">

          html,body
          {
          color: black; 	background-color: #ebebeb;

          font-size: 1em;
          font-family: Verdana;

          margin: 0; padding: 0;
          text-align: center;
          }

          body, html, div, p, i, strong, table {color:#606060; }
          img{border:0px;}
          div#Content img { margin: 7px 0;}

          p,i
          {
          margin: 0;
          padding: 3px 0px;
          }

          div#Content table
          {
          font-size: 1em;
          margin: 2px;
          }

          table td
          {
          padding: 3px 4px;
          margin: 0;
          }


          a:link
          {
          color: #c11111;
          }
          a:visited
          {
          color: #db4848;

          }
          a:active
          {
          color: #c11111;

          }
          a:hover
          {
          color: black;

          }


          div#page
          {
          text-align: left;
          margin: 0 auto ;
          width: 850px;
          padding:  20px 0 0 0 ;
          }


          div#Content
          {
          float: none;
          font-size: 0.7em;
          background-color: #fff;
          margin: 0 35px 30px 35px;
          padding: 0;
          width: auto;
          }
          * html div#Content
          {
          height: 1em;
          margin:  0 35px 30px 35px;
          padding:0;
          }

          h1
          {
          font-size: 13pt;
          }

          th
          {
          background-color: #eee;
          text-align: left;
          padding: 10px 4px;
          }

          td
          {
          border-bottom: 1px solid #eee;
          padding: 0;
          }

          .debug
          {
          color: gray;
          }

          .invisible
          {
          display:none;
          }

          .warn
          {
          color: #EFB54A;
          font-weight: bold;
          }

          .error
          {
          color: red;
          font-weight: bold;
          }


          .failure
          {
          color: #fff;
          background-color: #d80000;
          font-weight: bold;
          }

          .success
          {
          color: #ffffff;
          background-color: green;
          font-weight: bold;
          }



          fieldset
          {
          clear: both;
          font-size: 100%;
          border-color: #000000;
          border-width: 0;
          border-style: solid none none none;
          padding: 5px;
          margin: 3px 2px 10px 2px;
          }

          fieldset legend
          {
          font-size:	10pt;
          color: #555;
          font-weight: bold;
          margin: 0 0 0 -7px;
          padding: 10px 0 0 0;
          }
          label
          {
          float: left;
          text-align: right;
          width: auto;
          margin-right: 0em;
          padding: 2px 0;
          }
          input
          {
          float: left;
          margin-right: 30px;
          }

        </style>
        <script type="text/javascript">
          <![CDATA[ 
			function switchVisibility(firstclassName, excludeClassname)
			{
				var tr = document.getElementsByTagName('tr');
				for(var i=0;i<tr.length;i++)
				{
					if(tr[i].className.search(firstclassName + ' invisible')>=0 && (tr[i].className.search(excludeClassname)<0 || excludeClassname=="")) 
						tr[i].className = tr[i].className.replace(firstclassName + ' invisible', firstclassName);
					else if(tr[i].className.search(firstclassName)>=0 && (tr[i].className.search(excludeClassname)<0 || excludeClassname==""))
					  	tr[i].className = tr[i].className.replace(firstclassName, firstclassName + ' invisible');
				}
			}
			 ]]>
        </script>

      </head>
      <body>
        <div id="page">
          <div id="header-top">
            <h1 id="logo">
              <a href="#" title="Ranorex">
                <em>Ranorex</em>
              </a>
            </h1>
            <div id="small-nav"></div>
          </div>

          <div id="container">
            <div id="Content">
              <h1>
                <xsl:value-of select ="/log/@title"/>
              </h1>
              <fieldset>
                <legend>Log Level</legend>
                <label for="debug">Debug</label>
                <input type="checkbox" id="debug" name="debug" onClick="switchVisibility('debug','Validation');" checked="1" />
                <label for="info">Info</label>
                <input type="checkbox" id="info" name="info" onClick="switchVisibility('info','Validation');" checked="1" />
                <label for="warn">Warn</label>
                <input type="checkbox" id="warn" name="warn" onClick="switchVisibility('warn','Validation');" checked="1" />
                <label for="error">Error</label>
                <input type="checkbox" id="error" name="error" onClick="switchVisibility('error','Validation');" checked="1" />

                <label for="testresult">Test Result</label>
                <input type="checkbox" id="testresult" name="testresult" onClick="switchVisibility('failure','success');switchVisibility('success','failure')" checked="1" />

              </fieldset>
              <table border="0" cellspacing="0" width="100%">
                <tr>
                  <th width="15%" >
                    <b>Time</b>
                  </th>
                  <th width="10%" >
                    <b>Level</b>
                  </th>
                  <th width="15%" >
                    <b>Category</b>
                  </th>
                  <th>
                    <b>Message</b>
                  </th>
                </tr>
                <xsl:apply-templates select="//message"/>
              </table>

            </div>
            <div style="clear:both"></div>
            <div id="Footer"></div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <!--
  Template zum Einfuegen von Linefeeds:
  Alle in der Description angegebenen "<lf/>" TAGS werden in "<br/>" TAGS umgewandelt.
  -->
  <xsl:template match="lf">
    <br/>
  </xsl:template>

</xsl:stylesheet>


EDIT!
Here is what I do....

Code: Select all

 protected string ConvertXSLAndXMLToHTML(string xmlSource, string xslSource)
        {

            string resultDoc = Application.StartupPath + @"\result.html";
 
            try
            {
                XPathDocument myXPathDoc = new XPathDocument(xmlSource);
                XslTransform myXslTrans = new XslTransform();

                //load the Xsl 
                myXslTrans.Load(xslSource);

                //create the output stream
                XmlTextWriter myWriter = new XmlTextWriter(resultDoc, null);

                //do the actual transform of Xml
                myXslTrans.Transform(myXPathDoc, null, myWriter);

                myWriter.Close();
                
                        
                return (resultDoc);

            }

            catch (FileNotFoundException fileEx)
            {
                MessageBox.Show("File Not Found: " + fileEx.FileName, "File Not Found Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }


            catch (Exception ex)
            {
                MessageBox.Show("General Exception: " + ex.Message, "Exception Thrown", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

        }

Just as a random action I decided to try to find a syntax checker online to pass the function code into. I found this:

http://www.jslint.com/

copied the code in...and well it didnt go so well.

SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Re: Javascript Error in xsl file from report

Post by SeanP » Fri Apr 15, 2011 11:17 pm

Any update on this? I see the support team posting in other threads but not here. Any reason why?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Javascript Error in xsl file from report

Post by Ciege » Sat Apr 16, 2011 12:36 am

They may be looking into it and have not found out enough information to update you with...

However, in another post support says that
The report stylesheet is optimized for Internet Explorer. We do not recommend to use the Firefox browser to view Ranorex report files.
http://www.ranorex.com/forum/report-scr ... html#p8380

So it may be an issue with Firefox. Have you tried the same with IE?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Re: Javascript Error in xsl file from report

Post by SeanP » Mon Apr 18, 2011 5:02 pm

Yes I have tried it in Firefox and IE. My work around is the disable all debugging. This isnt something that I want to do as I am not sure if IE will be installed on the machines I will be running my projects on. Its a very specific environment.

The HTML is actually being bound to a .Net WebBrowser object and at runtime the javascript actually throws the error.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Javascript Error in xsl file from report

Post by Support Team » Tue Apr 19, 2011 1:14 pm

Hi,

Sorry but this is out of support, because we cannot support each custom modification from our users. I think if you debug your code and check your XSL file you will find the error. Just a hint, to check the XSL file drag and drop it to the IE and the IE will check if you XSL is valid.

Regards,
Peter
Ranorex Team
.
Image

SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Re: Javascript Error in xsl file from report

Post by SeanP » Tue Apr 19, 2011 5:18 pm

I am not sure how this is out of the context of support. The file in question is one that is automatically generated by Ranorex to style the report. The error itself comes from the javascript inside RanorexReport.xsl. Or are you saying that the conversion that .Net is doing of the xsl is causing the error? I dont think it is because the javascript is identical.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Javascript Error in xsl file from report

Post by Support Team » Wed Apr 20, 2011 7:50 am

Hi,

If you are using the whole RanorexReport3.xsl to convert your XML file to HTML, please use the following few lines of code to convert your report to HTML.
using System;
using System;
using System.Xml.Xsl;

namespace HtmlToXML
{
    class Program
    {
        static void Main(string[] args)
        {
            XslCompiledTransform xsl = new XslCompiledTransform();
            xsl.Load("RanorexReport3.xsl");
            xsl.Transform("test.xml", "test.html");
        }
    }
}
}
If you want to show the pictures inside the Report too, you have to copy them to the same folder.

Regards,
Peter
Ranorex Team
.
Image

SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Re: Javascript Error in xsl file from report

Post by SeanP » Wed Apr 20, 2011 4:25 pm

Support Team wrote:Hi,

If you are using the whole RanorexReport3.xsl to convert your XML file to HTML, please use the following few lines of code to convert your report to HTML.
using System;
using System;
using System.Xml.Xsl;

namespace HtmlToXML
{
    class Program
    {
        static void Main(string[] args)
        {
            XslCompiledTransform xsl = new XslCompiledTransform();
            xsl.Load("RanorexReport3.xsl");
            xsl.Transform("test.xml", "test.html");
        }
    }
}
}
If you want to show the pictures inside the Report too, you have to copy them to the same folder.

Regards,
Peter
Ranorex Team

Here is exactly what I do. Again the error does not come from the transformation it comes from the Javascript. Aside from that I also dont use RanorexReport3, I am just using RanorexReport.xsl''''

Code: Select all

 private string ConvertXSLAndXMLToHTML(string xmlSource, string xslSource)
        {

            string resultDoc = Application.StartupPath + @"\result.html";

            try
            {
                XPathDocument myXPathDoc = new XPathDocument(xmlSource);
                XslCompiledTransform myXslTrans = new XslCompiledTransform();

                //load the Xsl 
                myXslTrans.Load(xslSource);

                //create the output stream
                XmlTextWriter myWriter = new XmlTextWriter(resultDoc, null);

                //do the actual transform of Xml
                myXslTrans.Transform(myXPathDoc, null, myWriter);

                myWriter.Close();

                return (resultDoc);

            }

            catch (FileNotFoundException fileEx)
            {
                MessageBox.Show("File Not Found: " + fileEx.FileName, "File Not Found Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            catch (Exception ex)
            {
                MessageBox.Show("General Exception: " + ex.Message, "Exception Thrown", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

        }
       

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Javascript Error in xsl file from report

Post by Support Team » Thu Apr 21, 2011 8:08 am

Hi,

With my piece of code I get no JavaScript error. It seems your code affect the HTML in a different way. Please use the code above I posted.

Regards,
Peter
Ranorex Team
.
Image

SeanP
Posts: 60
Joined: Wed Sep 01, 2010 11:48 pm
Location: Irvine California

Re: Javascript Error in xsl file from report

Post by SeanP » Thu Apr 21, 2011 4:48 pm

Support Team wrote:Hi,

With my piece of code I get no JavaScript error. It seems your code affect the HTML in a different way. Please use the code above I posted.

Regards,
Peter
Ranorex Team
Do you have debugging turned on in IE?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Javascript Error in xsl file from report

Post by Support Team » Fri Apr 22, 2011 8:14 am

Hi,

Yes I have enabled the debugging in IE and I as said before, with my lines of code it works as expected.

Regards,
Peter
Ranorex Team
.
Image