Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2008, 07:42 PM
Authorized User
 
Join Date: Jan 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dved Send a message via Yahoo to dved
Default XSLT not executing java function(using SAXON)

Hi,

I am using saxon in XSLT to use my java extensions. XSLT calls a java function by passing a nodeset into it.

Java function grabs the nodeset. Since nodeset for java nothing but string , it appends the <xml version..> line and parse something like this:
 public String buildAndParseNodeset(String is){

String newIs="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +is;
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            StringReader reader = new StringReader( newIs );
            InputSource inputSource = new InputSource( reader );

             Document doc = docBuilder.parse(inputSource);
             NodeList listOfTmPoints = doc.getElementsByTagName("ns1:TmPoint");

....

return st;



}

At the end this will return a string(a HTML ) which will be inserted in xslt.

The whole problem is when I use this program as a standalone java application, it works good.

BUT when I use it in my XSL it gives me a fatal error something like this:(Content is not allowed in prolog)



C:\Users\Deep\Desktop\saxonsa8-9-0-4j>java -cp .;/c:/Users/Deep/Desktop/saxonsa8
-9-0-4j/saxon8.jar net.sf.saxon.Transform -TJ template.xml generateTable.xsl
Loading com.ercot.tpo.ParseNodeSet
Looking for method buildAndParseNodeset in Java class class com.ercot.tpo.ParseN
odeSet
Number of actual arguments = 1
Trying method display: name does not match
Trying method buildAndParseNodeset: name matches
Method is static
Method has 1 argument; expecting 1
Found a candidate method:
    public static java.lang.String com.ercot.tpo.ParseNodeSet.buildAndParseNodes
et(java.lang.String)
Trying method hashCode: name does not match
Trying method getClass: name does not match
Trying method wait: name does not match
Trying method wait: name does not match
Trying method wait: name does not match
Trying method equals: name does not match
Trying method toString: name does not match
Trying method notify: name does not match
Trying method notifyAll: name does not match
[Fatal Error] :1:1: Content is not allowed in prolog.
** Parsing error, line 1, uri null
 Content is not allowed in prolog.
<html xmlns:parse="java:com.ercot.tpo.ParseNodeSet">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   </head>
   <body>
      <table id="tbl" border="0" cellpadding="0" cellspacing="0" style="border:b
lack solid 1px;border-left:0px" class="copyacross right"></table>
   </body>
</html>
C:\Users\Deep\Desktop\saxonsa8-9-0-4j>


If any one has any idea please let me know what m I doing wrong.

Thanks




Thanks
Dved
__________________
Thanks
Dved
 
Old January 15th, 2008, 08:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A "node-set" in XSLT (you're using XSLT 1.0 terminology, but never mind) is a set of nodes, that is, it's the tree representation of some XML data. Your Java method is expecting a string in the form of unparsed lexical XML. You seem to be expecting that the system will work this out for itself, and "unparse" the data (that is, serialize it) to meet the expectations of your function. Well, it doesn't. There is no reason why the string should be well-formed XML, so it's not surprising that the XML parser throws it out.

Why are you trying to parse it anyway? You don't need to, it's already been parsed. For that matter, why are you using an extension function to do something that would be much better done in XSLT?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 15th, 2008, 08:46 PM
Authorized User
 
Join Date: Jan 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dved Send a message via Yahoo to dved
Default

Well,

This is to be done due to performance issues. I dont have whole picture why it needs to be done but this is how it should be done.

I got the point about the node-set. But then what should I do. Inorder to get a document handle I do this. I am novice in using Java. Please let me know how do i get handle to the node-set in java function.

If I dont get a document handle I can not traverse the nodes one by one. If I can, let me know.

Also the question I have is: When a nodeset is passed from XSL(using java function), is it in a specific datastructure. What I mean is will my java function will be like public string myFunction(Nodeset ns){..}

Please let me know how to go about writing this program.

Thanks a lot for your suggestions.






Thanks
Dved





Similar Threads
Thread Thread Starter Forum Replies Last Post
Jumping into java extensions to Saxon mphare XSLT 2 April 29th, 2008 10:02 PM
Executing Saxon from de Command Line Tomi XSLT 2 December 13th, 2007 04:58 AM
Saxon java question amhicraig XSLT 1 December 7th, 2007 01:21 PM
calling saxon from java program Tomi XSLT 1 July 31st, 2006 06:57 AM
Java Extension Function in XSLT Mostafa XSLT 1 January 18th, 2005 11:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.