[xalan] FATAL ERROR: could not compile stylesheet

Z

z-man

Hello all

I'm trying to run an XSLT transformation using JDK 1.5.0, but I get an
exception (see below).
The strange thing is that using the *same* code & stylesheet on JDK 1.4,
it works!

Specifically, when I invoke a new transformer
(TransformerFactory.newInstance().newTransformer(...)) xalan cries that
it can't compile the stylesheet because a parameter of its is undefined
(you guess: how could I set a parameter *before* instantiating the
corresponding transformer?! It's a proverbial matter of chicken & egg...)!

Many thanks for your suggestions!

***** Here it is the call stack:
java.lang.ClassCastException:
com.sun.org.apache.xalan.internal.xsltc.compiler.Param
at
com.sun.org.apache.xalan.internal.xsltc.compiler.SymbolTable.addVariable(SymbolTable.java:79)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Variable.parseContents(Variable.java:86)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseOwnChildren(Stylesheet.java:580)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseContents(Stylesheet.java:562)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Import.parseContents(Import.java:115)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseOwnChildren(Stylesheet.java:590)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseContents(Stylesheet.java:562)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:380)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:325)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:410)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:791)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:619)
at mine.PageBuilder.main(PageBuilder.java:89)
ERROR: 'file:///home/xyz/styles/page.teg.xhtml.xsl: line 56: Variable
or parameter 'site' is undefined.'
FATAL ERROR: 'Could not compile stylesheet'

***** Here they are the affected mine.PageBuilder.main() lines of code:
File stylesheet = ... // That's OK.
Transformer transformer = null;
try
{
transformer = TransformerFactory.newInstance().newTransformer(
new StreamSource(stylesheet.getCanonicalPath())
);
}
catch(Exception exception)
{
printError(exception); // Here it is where my exception is trapped
(sob!).
}
transformer.setParameter("sourcePath", this.sourcePath); // Here it is
where I should define (god willing...) my stylesheet param (just *after*
the /failed/ creation of the transformer).

***** Here it is the stylesheet
(file:///home/xyz/styles/page.teg.xhtml.xsl) that xalan cannot compile:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:teg="http://www.something.com/tegumento"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="teg teg-ext html"
version="1.0"<xsl:param name="sourcePath">
<!-- Data source absolute path. -->
</xsl:param>
<xsl:variable name="site" select="document(concat($sourcePath,
'site.teg'))/teg:site"/>
....
<!-- This is the line 56 that raises the error "Variable or parameter
'site' is undefined.' FATAL ERROR: 'Could not compile stylesheet'" -->
<meta name="keywords" content="{$site/teg:info/teg:keywords},
{teg:info/teg:keywords}"/>
....
 
T

Thomas Hawtin

Arvind said:
hope you are sure, that a xsl:variable be outside a xsl:template tag ?

Yeah it's allowed but has completely different semantics. Gotta love XSLT.

Tom Hawtin
 
Z

z-man

hope you are sure, that a xsl:variable be outside a xsl:template tag ?

That's not the point (global variables are spec-compliant), but you
nearly got it (thank you!).

First of all, I wanna say that I eventually caught it: it was a subtle
violation that curiously wasn't enforced by the previous version of
xalan shipped along with JDK 1.4.
To be honest, I oversimplified the real composition of the stylesheet
(see below): I'm sorry, but I feared to clutter my post with overcrowded
dumps!
In more detail, my stylesheet is made up by a main file (the one I've
already shown you) and an imported one (gathering common templates
reused in diverse contexts).
The main file exposes the same sourcePath param declared by the imported
one, but the latter wrongly uses the xsl:variable element (instead of
the appropriate xsl:param): it was just the matter of substituting such
an erroneous declaration to get all the things working snappily.

Best regards,
z-man.

***** Main stylesheet:
....
<xsl:import href="common.teg.xhtml.xsl"/>
<xsl:param name="sourcePath">
<!-- Data source absolute path. -->
</xsl:param>
....
<!-- This is the line 56 that raises the error "Variable or parameter
'site' is undefined.' FATAL ERROR: 'Could not compile stylesheet'" -->
<meta name="keywords" content="{$site/teg:info/teg:keywords},
{teg:info/teg:keywords}"/>
....

***** Imported stylesheet "common.teg.xhtml.xsl" (vicious):
....
<!-- Here it is the BIG PROBLEM (SOLVED): variable instead of param! -->
<xsl:variable name="sourcePath">
<!-- Data source absolute path. -->
</xsl:variable>
<xsl:variable name="site" select="document(concat($sourcePath,
'site.teg'))/teg:site"/>
....

***** Imported stylesheet "common.teg.xhtml.xsl" (valid):
....
<!-- Now the flaw is fixed (and all the stylesheets lived happily ever
after, crunching exquisite xml files...) -->
<xsl:param name="sourcePath">
<!-- Data source absolute path. -->
</xsl:param>
<xsl:variable name="site" select="document(concat($sourcePath,
'site.teg'))/teg:site"/>
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top