You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2001/02/14 16:28:05 UTC

Re: Errors to stderr/out AND no output at all AND meta-data not allowed

See my comments below.

Gary

> Daryl Beattie wrote:
> 
> Dear Xalan Developers,
> 
>         Sorry for this triple-whammy e-mail, but I didn't want to
> bombard the list with three concurrent messages that all relate to the
> same piece of code. I am using Xalan-J2, WinNT, JDK1.2.2. I have
> attached my style sheet.
> 
> 1        I get the following to standard out (or standard error):
> 
> file:///c:/projects/siteware/SITEWare/xslt/smml2javascript.xsl; Line
> 532; Column 66; VariableReference given for variable out of context or
> without definition!  Name = art
> 
>         Shouldn't this throw an exception instead? The very strange
> thing is that I get this error only once in about every 10 runs of my
> program. Could it be that the progam exits before flushing stdout/err?
> I thought that these flushed when programs quit -- although it could
> be that my debugger doesn't catch this output.
>         There might be something wrong in the way I am using Xalan:
> 
> // Get the transformer for performing the transformtaion.
> Transformer transformer = primaryFormat.getTransformer(tdmlXsl);
> 
> try {
>     StringWriter sw = new StringWriter();
>     // Perform the transformation (the output is redirected by the
> style sheet to other files).
>     transformer.transform(new
> javax.xml.transform.stream.StreamSource(fSmmlFile), new
> javax.xml.transform.stream.StreamResult(sw));
> }
> catch (NullPointerException npe) {
>     ErrorHandler.printerr("Error", "SectionThread", "primTransform()",
> "Empty Style sheet transformer: ", npe);
> }
> catch (TransformerException te) {
>     ErrorHandler.printerr("Error", "SectionThread", "primTransform()",
> "XML TRANSFORMATION ERROR!", te);
>     //throw new ContentWriterException();
> }
> 

I think that the XalanJ2 is throwing an exception and it is being caught
somewhere where it's just printing this line.  Try adding a 
  catch (Exception e) {
    e.printStackTrace();
  }
clause to the bottom of your existing code and that should catch the
exception and print it with a stack trace so we can see where it's
coming from.  Also, you could print the fSmmlFile name or the file
itself so that we can catch the XML that's causing this error and try to
reproduce the problem from the command line which will make debugging
easier.

> 2        Which brings me to my second question. The way I perform XSL
> transformations is "different"; in that I have a default wrapper
> stylesheet that xsl:imports the sheet the user specifies. This wrapper
> style sheet redirects the output to a file (whose name it constructs
> at runtime). That is the reason for the strange line above (in dark
> green) that creates a StringWriter and uses it to store the
> transformation result without ever saving the results -- I expect the
> output to be redirected to a file. For some reason, no file is
> written. This same technique works fine with similar code that uses
> Xalan1. Any ideas? Is it a usage issue? It could be that it's because
> of the error in problem #1, which rarely shows up.

Is a file ever written, even when there is no error?  One thing you
might try is changing the xmlns:redirect namespace declaration to the
proper declaration for XalanJ2:

  xmlns:redirect="org.apache.xalan.lib.Redirect"

The XalanJ2 code should also handle the old name which you're using but
that might be part of the problem.  Do you get the expected output if
you comment out the <redirect:write ..> and </redirect:write> elements?

> 
> 3        The third question I have is regarding the following error:
> 
> javax.xml.transform.TransformerConfigurationException: metadata is not
> allowed in this position in the stylesheet!
> 
>         You will notice in the style sheet I have attached that there
> is a "scrm:metadata" section. This section wasn't always in the "scrm"
> namespace, so it used to look like:
> 
> <metadata>
>         [same contents without "scrm" namespace]
> </metadata>
> 
>         It is when the metadata looks like the above that I get the
> error shown above. I was under the impression -- which may be a false
> one -- that Xalan would ignore anything not in the xsl namespace that
> was not inside an xsl:template (or something). I may be completely
> wrong about this! But I do know that having the <metadata> there never
> caused any problems with Xalan1. If this is a place where Xalan1 is
> wrong and Xalan2 is right, then I might have to go through all of my
> style sheets and make corrections similar to the ones I made in the
> attached file. Adding the scrm namespace seems to remove the
> error. This said, I'm really just wondering if this is XalanJ2 acting
> up, or whether it's not a problem at all.