You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Ashay <as...@yahoo.com> on 2003/04/22 13:32:18 UTC

problem with XSLT tranformation using Xalan

Hi, I am very new to Xerces and Xalan.I am using Xerces 2.1.0 and Xalan 1.4.0. Based on one of the examples given on the Apache site, I wrote the below given simple code and got the following error message while transforming a XalanDocument.I am getting -2 as a result of XalanTransformer::tranform() method. Error msg:Fatal Error at (file <unknown>, line 0, column 0): An exception occurred!
Type:RuntimeException, Message:The primary document entity could not be
opened. Id={null}
theResult = -2 Could someone give me pointers as to why this error is caused. A speedy reply would be highly appreciated.Thanks in advance. The code:**************************************************************************// Use the Xerces DOM parser to create a DOM_Document.
#include <parsers/DOMParser.hpp>
#include <dom/DOM_Node.hpp>DOMParser  theParser;
// You MUST instruct the Xerces DOMParser NOT to create a DOM_XMLDecNode
// in the DOM to represent the XML declaration. See "Limitations" below.
DOMParser::setToCreateXMLDeclTypeNode(false);
theParser.parse("foo.xml");
const DOM_Document theDOM = theParser.getDocument();// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
XercesDOMSupport   theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDoc = theParserLiaison.createDocument(theDOM);// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource  theInputSource(theDoc);XSLTInputSource theXSLInput("foo.xsl");XSLTResultTarget theOutput("foo.out");XalanTranformer::intialize();
XalanTransformer theTransformerint theResult = theTransformer.transform(theInputSource,theXSLInput,theOutput);cout << "theresult is: " << theResult ;
****************************************************************************




---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

Re: problem with XSLT tranformation using Xalan

Posted by "Thomas F. O'Connell" <tf...@netcentral.com>.
So it would seem there are (at least) two methodologies for transforming an
XML document one wants to ensure has been validated.

1. parse and validate foo.xml with Xerces.
   pass a XercesDOMWrapperParsedSource version of foo.xml to Xalan.

2. parse and validate foo.xml with Xerces.
   transform with Xalan under the assumption that foo.xml has been parsed.

Is the method specified in the usage patterns (i.e., method #1 above) the
recommended method?

-tfo

On Tue, Apr 22, 2003 at 08:35:54AM -0700, david_n_bertoni@us.ibm.com wrote:
> Unless you really need to use the Xerces DOM, you should avoid it.  Here's
> a much simpler version without it:
> 
>    XalanTranformer::intialize();
>    {
>        XalanTransformer theTransformer;
>        int theResult =
>        theTransformer.transform("foo.xml","foo.xsl","foo.out");
>        cout << "theResult is: " << theResult ;
>    }
> 
>    XalanTransformer::terminate();
> 
> If you really need to use the Xerces DOM, see the ParsedSourceWrappers
> sample, or this usage pattern:
> 
>    http://xml.apache.org/xalan-c/usagepatterns.html#xercesdomwrapperparsedsource

Re: problem with XSLT tranformation using Xalan

Posted by Ashay <as...@yahoo.com>.
Hi David, I tried out the tranformation of an xml file the same way you've stated below and it worked fine. But my requirement is to transform a document of type XalanDocument* . An XSLTInputSource object can be created with a XalanDocument object which can then be passed to the transform() method. But this does not seem to be working and gives me the error that I mentioned. Any ideas what could be causing this error or what I might be missing in my code. 



david_n_bertoni@us.ibm.com wrote:



Unless you really need to use the Xerces DOM, you should avoid it. Here's
a much simpler version without it:

XalanTranformer::intialize();
{
XalanTransformer theTransformer;
int theResult =
theTransformer.transform("foo.xml","foo.xsl","foo.out");
cout << "theResult is: " << theResult ;
}

XalanTransformer::terminate();

If you really need to use the Xerces DOM, see the ParsedSourceWrappers
sample, or this usage pattern:

http://xml.apache.org/xalan-c/usagepatterns.html#xercesdomwrapperparsedsource

Dave




Ashay 
.com> cc: (bcc: David N Bertoni/Cambridge/IBM) 
Subject: problem with XSLT tranformation using Xalan 
04/22/2003 04:32 
AM 




Hi,

I am very new to Xerces and Xalan.
I am using Xerces 2.1.0 and Xalan 1.4.0.

Based on one of the examples given on the Apache site, I wrote the below
given simple code and got the following error message while transforming a
XalanDocument.
I am getting -2 as a result of XalanTransformer::tranform() method.

Error msg:
Fatal Error at (file , line 0, column 0): An exception occurred!
Type:RuntimeException, Message:The primary document entity could not be
opened. Id={null}
theResult = -2

Could someone give me pointers as to why this error is caused. A speedy
reply would be highly appreciated.
Thanks in advance.

The code:
**************************************************************************
// Use the Xerces DOM parser to create a DOM_Document.
#include 

#include 
DOMParser theParser;
// You MUST instruct the Xerces DOMParser NOT to create a DOM_XMLDecNode
// in the DOM to represent the XML declaration. See "Limitations" below.
DOMParser::setToCreateXMLDeclTypeNode(false);
theParser.parse("foo.xml");
const DOM_Document theDOM = theParser.getDocument();
// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDoc = theParserLiaison.createDocument(theDOM);
// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource theInputSource(theDoc);
XSLTInputSource theXSLInput("foo.xsl");
XSLTResultTarget theOutput("foo.out");
XalanTranformer::intialize();
XalanTransformer theTransformer
int theResult =
theTransformer.transform(theInputSource,theXSLInput,theOutput);
cout << "theresult is: " << theResult ;

****************************************************************************



Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.





---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

Re: problem with XSLT tranformation using Xalan

Posted by da...@us.ibm.com.



Unless you really need to use the Xerces DOM, you should avoid it.  Here's
a much simpler version without it:

   XalanTranformer::intialize();
   {
       XalanTransformer theTransformer;
       int theResult =
       theTransformer.transform("foo.xml","foo.xsl","foo.out");
       cout << "theResult is: " << theResult ;
   }

   XalanTransformer::terminate();

If you really need to use the Xerces DOM, see the ParsedSourceWrappers
sample, or this usage pattern:

   http://xml.apache.org/xalan-c/usagepatterns.html#xercesdomwrapperparsedsource

Dave



                                                                                                                                 
                      Ashay                                                                                                      
                      <ashaytech@yahoo         To:      xalan-c-users@xml.apache.org                                             
                      .com>                    cc:      (bcc: David N Bertoni/Cambridge/IBM)                                     
                                               Subject: problem with XSLT tranformation using Xalan                              
                      04/22/2003 04:32                                                                                           
                      AM                                                                                                         
                                                                                                                                 



Hi,

I am very new to Xerces and Xalan.
I am using Xerces 2.1.0 and Xalan 1.4.0.

Based on one of the examples given on the Apache site, I wrote the below
given simple code and got the following error message while transforming a
XalanDocument.
I am getting -2 as a result of XalanTransformer::tranform() method.

Error msg:
Fatal Error at (file <unknown>, line 0, column 0): An exception occurred!
Type:RuntimeException, Message:The primary document entity could not be
opened. Id={null}
theResult = -2

Could someone give me pointers as to why this error is caused. A speedy
reply would be highly appreciated.
Thanks in advance.

The code:
**************************************************************************
// Use the Xerces DOM parser to create a DOM_Document.
#include <parsers/DOMParser.hpp>
#include <dom/DOM_Node.hpp>
DOMParser  theParser;
// You MUST instruct the Xerces DOMParser NOT to create a DOM_XMLDecNode
// in the DOM to represent the XML declaration. See "Limitations" below.
DOMParser::setToCreateXMLDeclTypeNode(false);
theParser.parse("foo.xml");
const DOM_Document theDOM = theParser.getDocument();
// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
XercesDOMSupport   theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDoc = theParserLiaison.createDocument(theDOM);
// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource  theInputSource(theDoc);
XSLTInputSource theXSLInput("foo.xsl");
XSLTResultTarget theOutput("foo.out");
XalanTranformer::intialize();
XalanTransformer theTransformer
int theResult =
theTransformer.transform(theInputSource,theXSLInput,theOutput);
cout << "theresult is: " << theResult ;

****************************************************************************



Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.