Project

Profile

Help

PHP5 & Saxon XSLT Parse Error

Added by Anonymous almost 16 years ago

Legacy ID: #5187295 Legacy Poster: David Trang (davidhtrang)

Hi guys, I really need some help with this. I'm new to PHP and XSLT Parsers and I am trying to get this working. I was looking at php.net to find a parser for PHP5 and came across Saxon and found some sample code there also (below). When I installed Java Bridge and Saxon I started to play around with the parser, parsing the books.xml and books.xsl through the command line and it worked fine. What I needed was to have something working in PHP5 so I could do it through a website. When I used the sample code I get a error message "net.sf.saxon.trans.XPathException: whitespace required" which I don't understand what that means but I have localized it to this line "$oTransFormer->transform($oXmlSource, $oResultStream);" is there a way to get better error messages or does anyone know why this is happening? Any help would be much appreciated. Thanks! Directory where the jar files are located define("SAXON_DIR", $_SERVER['DOCUMENT_ROOT']."/saxonb8.9.0/"); include the jars java_require(SAXON_DIR." saxon8.jar;".SAXON_DIR."saxon8-dom.jar"); $sXslFile = $_SERVER['DOCUMENT_ROOT']."/myfirst.xsl"; The xsl file $sXmlFile = $_SERVER['DOCUMENT_ROOT']."/myfirst.xml"; The xml file try { $oXslSource = new java("javax.xml.transform.stream.StreamSource", "file:".$sXslFile); $oXmlSource = new java("javax.xml.transform.stream.StreamSource", "file:".$sXmlFile); $oFeatureKeys = new JavaClass("net.sf.saxon.FeatureKeys"); Create the Factory $oTransformerFactory = new java("net.sf.saxon.TransformerFactoryImpl"); Disable source document validation $oTransformerFactory->setAttribute($oFeatureKeys->SCHEMA_VALIDATION, 4); Create a new Transformer $oTransFormer = $oTransformerFactory->newTransformer($oXslSource); Create a StreamResult to store the output $oResultStringWriter = new java("java.io.StringWriter"); $oResultStream = new java("javax.xml.transform.stream.StreamResult", $oResultStringWriter); Transform $oTransFormer->transform($oXmlSource, $oResultStream); Echo the output from the transformation echo java_cast($oResultStringWriter->toString(), "string"); } catch(JavaException $e){ echo java_cast($e->getCause()->toString(), "string"); exit; }


Replies (4)

Please register to reply

RE: PHP5 & Saxon XSLT Parse Error - Added by Anonymous almost 16 years ago

Legacy ID: #5202558 Legacy Poster: Michael Kay (mhkay)

I thought I had replied to this (did you post to both the forum and the list perhaps?) I'm afraid I don't know much about PHP and its Java bridge. In particular, the way that exceptions are handled. But I suspect there is a lot more information in the Java exception than you are displaying. If the underlying exception is a net.sf.saxon.trans.XPathException, try calling its printStackTrace() method, which will show any nested exceptions, or calling getMessageAndLocation() which will show any location information, or getErrorCode() which will show the error code. The message "whitespace required" is not generated by Saxon itself (at least not in a current release, I haven't looked in 8.9), so it must come from some underlying software, most probably the XML parser. Have you tried parsing the source document directly, rather than through Saxon?

RE: PHP5 & Saxon XSLT Parse Error - Added by Anonymous almost 16 years ago

Legacy ID: #5203870 Legacy Poster: David Trang (davidhtrang)

Sorry Michael, I thought this was were I was supposed to post the question. Where is this forum and list that you are talking about?

RE: PHP5 & Saxon XSLT Parse Error - Added by Anonymous almost 16 years ago

Legacy ID: #5203925 Legacy Poster: Michael Kay (mhkay)

It's fine to use the forum. There is also a mailing list, also called saxon-help - go to SourceForge "mailing lists". The mailing list is more interactive - you are more likely to get help from other Saxon users, not just from me. All I meant in my response was that I must have made a mistake when previously responding.

RE: PHP5 & Saxon XSLT Parse Error - Added by Anonymous almost 16 years ago

Legacy ID: #5206075 Legacy Poster: David Trang (davidhtrang)

Oh no I didn't take offense to it or anything like that. I just couldn't find the mailing list and I thought this is what you meant. I think I found it now though, I hope. LOL. Thanks so much Michael!

    (1-4/4)

    Please register to reply