?
Solved

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

Posted on 2006-11-26
11
Medium Priority
?
762 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 
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
 

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 2000 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

752 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