Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [xalan] FATAL ERROR: could not compile stylesheet

Reply
Thread Tools

[xalan] FATAL ERROR: could not compile stylesheet

 
 
z-man
Guest
Posts: n/a
 
      04-13-2006
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.P aram
at
com.sun.org.apache.xalan.internal.xsltc.compiler.S ymbolTable.addVariable(SymbolTable.java:79)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.V ariable.parseContents(Variable.java:86)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.S tylesheet.parseOwnChildren(Stylesheet.java:580)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.S tylesheet.parseContents(Stylesheet.java:562)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.I mport.parseContents(Import.java:115)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.S tylesheet.parseOwnChildren(Stylesheet.java:590)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.S tylesheet.parseContents(Stylesheet.java:562)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.P arser.createAST(Parser.java:380)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.X SLTC.compile(XSLTC.java:325)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.X SLTC.compile(XSLTC.java:410)
at
com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerFactoryImpl.newTemplates(TransformerFactoryI mpl.java:791)
at
com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerFactoryImpl.newTransformer(TransformerFactor yImpl.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
xmlnssl="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"
>

<xslaram name="sourcePath">
<!-- Data source absolute path. -->
</xslaram>
<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}"/>
....
 
Reply With Quote
 
 
 
 
Arvind
Guest
Posts: n/a
 
      04-13-2006
hope you are sure, that a xsl:variable be outside a xsl:template tag ?


--
Arvind

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      04-14-2006
z-man wrote:
> java.lang.ClassCastException:
> com.sun.org.apache.xalan.internal.xsltc.compiler.P aram
> at
> com.sun.org.apache.xalan.internal.xsltc.compiler.S ymbolTable.addVariable(SymbolTable.java:79)


From the source it looks like the problem is with hiding a parameter
with a variable. So I guess avoid name reuse.

Looks similar to this bug, possibly:
http://issues.apache.org/jira/browse...-1665?page=all

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      04-14-2006
Arvind wrote:
> 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
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
z-man
Guest
Posts: n/a
 
      04-14-2006
On 04/14/2006 01:02 AM, Arvind wrote:
> hope you are sure, that a xsl:variable be outside a xsl:template tag ?
>
> --
> Arvind
>


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 xslaram): 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"/>
<xslaram name="sourcePath">
<!-- Data source absolute path. -->
</xslaram>
....
<!-- 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...) -->
<xslaram name="sourcePath">
<!-- Data source absolute path. -->
</xslaram>
<xsl:variable name="site" select="document(concat($sourcePath,
'site.teg'))/teg:site"/>
....
 
Reply With Quote
 
z-man
Guest
Posts: n/a
 
      04-14-2006
On 04/14/2006 09:56 AM, Thomas Hawtin wrote:
> z-man wrote:
>> java.lang.ClassCastException:
>> com.sun.org.apache.xalan.internal.xsltc.compiler.P aram
>> at
>> com.sun.org.apache.xalan.internal.xsltc.compiler.S ymbolTable.addVariable(SymbolTable.java:79)

>
> From the source it looks like the problem is with hiding a parameter
> with a variable. So I guess avoid name reuse.
>
> Looks similar to this bug, possibly:
> http://issues.apache.org/jira/browse...-1665?page=all
>
> Tom Hawtin


Tom, you are THE MAN!
I hadn't read your message while I was replying to Arvind, but you
definitely got it: 1 billion points!

Thanks to all you, guys!

Arrivederci
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Exception: FATAL ERROR: 'Could not compile stylesheet' vinnuavc Java 0 07-25-2008 11:31 AM
Firefox and XSLT (local stylesheet works, server-based stylesheet fails) David Blickstein XML 14 10-15-2005 11:27 PM
xml:stylesheet use in document with multiple stylesheet options David Blickstein XML 3 08-02-2005 03:10 PM
have a stylesheet generate another stylesheet based on XML? Steven An XML 1 11-23-2004 01:07 PM
Stylesheet referanse i stylesheet =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?= XML 3 07-04-2004 03:16 PM



Advertisments