Solved

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

Posted on 2006-11-26
11
754 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get last 10 digits of an xsl value-of field 7 59
C# SQL BULK INSERT CLASS 5 47
Help with Syntax 9 36
Issue with XSLT mapping 10 35
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. 
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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