Solved

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

Posted on 2006-11-26
11
750 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 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

21 Experts available now in Live!

Get 1:1 Help Now