• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 770
  • Last Modified:

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

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
phobis
Asked:
phobis
  • 5
  • 4
1 Solution
 
Geert BormansCommented:
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
 
phobisAuthor Commented:
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
 
Geert BormansCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Geert BormansCommented:
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
 
phobisAuthor Commented:
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
 
phobisAuthor Commented:
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
 
Geert BormansCommented:
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
 
phobisAuthor Commented:
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
 
Geert BormansCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now