Solved

Help using Sarissa library for and client-side XSLT transformation.

Posted on 2006-11-26
11
747 Views
Last Modified: 2008-01-09
Help using Sarissa library for and client-side XSLT transformation.

I have javascript that takes a string of XML and calls a remote XSLT file. Then when I attempt a transformation, I get the error:
      "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXSLTProcessor.importStylsheet]

This is the XSLT file location:
      http://pdn.sieris.com/sieris/core8/skins/default/ajax.xslt

Here is a the javascript that I am using:
      var xmlDoc = Sarissa.getDomDocument();
      var xsltDoc = Sarissa.getDomDocument();
      var processor = new XSLTProcessor();
      var xmlHttp = new XMLHttpRequest();
      
      xmlDoc = (new DOMParser()).parseFromString("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><ajax>" + data + "</ajax>", "text/xml");
                  
      xsltDoc.async = false;
      xsltDoc.load(jsskin + 'ajax.xslt');
            
      processor.importStylesheet(xsltDoc);
      
      alert(new XMLSerializer().serializeToString(xmlDoc));
      var resultDocument = processor.transformToDocument(xmlDoc);
      alert(new XMLSerializer().serializeToString(resultDocument));

Any help is greatly appriciated.  :)
0
Comment
Question by:phobis
  • 5
  • 4
11 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18015586
Hi phobis,

the above code works like a charm for me (tested in Firefox and IE7)
I have some observations though

- do you have data well defined, and is it a string?
- do you have jsskin well defined and is it the correct absolute or relative path to the stylesheet?
- you are not exactly making XML in your test stylesheet, I changed it a little to create XML
                <?xml version="1.0" encoding="iso-8859-1"?>
                <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  <xsl:output method="xml"/>
                    <xsl:template match="/ajax" >
                        <test>ok</test>
                    </xsl:template>
                </xsl:stylesheet>
- I also removed the include line, because it did not mean anything to me
Are you sure that the inclusion happens correctly? That could be a trickier bit
- why do you have the xmlHttp?

Cheers!
0
 

Author Comment

by:phobis
ID: 18016153
OK, thanks Gertone...

- Data is well defined.
- jsskin is als well defined.
- I changed the xslt file and now it works (when there are no includes)
- When I add the includes... everything stops working. Do you know how an include can be made to work with the Sarissa library?
- The xmlHttp variable was left over from previous experimenting. I removed that as well.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18017845
phobis,

well, I did some tests
xsl:include works fine with Sarissa, that is not the problem
I think the problem is finding the included file
If I put everything in the same directory, it all works well
IE says it can't find the object if I change the filename, FF says nothing (simply blank page in your example)

I bet the problem is the exact path to your include file
Maybe you will have to find a way to pass jsskin into the XSLT for the inclusion
(since it will not work with a parameter, you will need to change the XSLT object using DOM)
or choose a path relative to where the html file is

cheers

Geert
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18018178
By the way,

I am still deciding on which library to use in a near future JS project
I need a lot of XSLT in different browsers there,
and I will likely be using Sarissa.

I am very interested to hear what made you choose for Sarissa?
Have you evaluated alternatives?

Thanks

Geert
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:phobis
ID: 18018859
I have seen a few alternatives... Like Google's framework. I choose this mainly from popularity. It may not be the best choice. I will experiment with others.
If you know of any alternatives, please post them. Thanks.
0
 

Author Comment

by:phobis
ID: 18019584
OK. I have attempted to fix the issue as you have instructed. I have gotten further.

Now... If you go to this page:
http://pdn.sieris.com/sieris/core8/example-page.php

You will see what problem I am running into.

Ignore the first two Alert Boxes.
The third Alert Box is the xml being passed in.
The fourth Alert Box is the transformed output.

The output has an element "transformix"

Why am I getting this?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18021152
phobis,

well, something wrong with your XSLT I am afraid
The fourth alert is blank in IE, the fifth says "ok3"
or the other way round.
I see no xml tags appearing in the two last alerts in IE

The transformiix node is refering to the XSLT project for Mozilla (code name transformiix)
http://www.mozilla.org/projects/xslt/
so I assume you only get that in FireFox

You should not get that though,
so I am afraid this is a fallback from an erroneous action
I looked at the projects open bugs,
but I don't find any information

I think it is a good idea to make sure that your xslt is doing the right thing and that you are really spitting out XML as a result

cheers

Geert

0
 

Author Comment

by:phobis
ID: 18028361
OK.. I think this will solve my issue.. if I could get your help debugging this XSLT.

I have this XML in a file:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="skins/default/ajax.xslt"?>
<ajax>
      <text>
            random number -&gt; 760<br/>And 8 line breaks.<br/><br/><br/><br/><br/><br/><br/><br/>
      </text>
</ajax>

I also have this XSLT in a file:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" omit-xml-declaration="yes"/>
      <xsl:template match="/ajax">
                  <xsl:call-template name="test">
                        <xsl:with-param name="thisNode" select="."/>
                  </xsl:call-template>
      </xsl:template>
      <xsl:template name="test">
            <xsl:param name="thisNode"/>
            <xsl:for-each select="$thisNode/child::text">
                  <xsl:for-each select="./node()">
                        <xsl:copy-of select="."/>
                  </xsl:for-each>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>



This is not working for some reason. Please help, I can't seem to figure it out.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 18028948
phobis,

well, you add a doctype,
but in order to get that in the output,
you need at least wellformed XML or HTML,
so you would need a root tag

I assumed you want html from the doctype,
so here is a

I added some logic to check if a node is a text node with some length,
in order to create a p element
this gives us more or less sensible html

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" method="html" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <html>
            <body>
                    <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="ajax">
        <xsl:call-template name="test">
            <xsl:with-param name="thisNode" select="."/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="test">
        <xsl:param name="thisNode"/>
        <xsl:for-each select="$thisNode/text">
            <xsl:for-each select="node()">
                <xsl:choose>
                    <xsl:when test="string-length(normalize-space(.)) &gt; 0">
                        <p><xsl:copy-of select="."/></p>
                    </xsl:when>
                    <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>



By the way,
I have not checked too much alternatives for Sarissa
It gives me what I need, I just wondered if you did an analysis

cheers

Geert
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML problem with Internet Explorer 7 29
c# advanced xml like string split - Help needed 15 66
Problem to DocumentFormat 8 67
XSLT Help 12 19
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now