[xalan] FATAL ERROR: could not compile stylesheet

Discussion in 'Java' started by z-man, Apr 13, 2006.

  1. z-man

    z-man Guest

    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}"/>
    ....
    z-man, Apr 13, 2006
    #1
    1. Advertising

  2. z-man

    Arvind Guest

    Re: FATAL ERROR: could not compile stylesheet

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


    --
    Arvind
    Arvind, Apr 14, 2006
    #2
    1. Advertising

  3. z-man wrote:
    > 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)


    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/XALANJ-1665?page=all

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Apr 14, 2006
    #3
  4. Re: FATAL ERROR: could not compile stylesheet

    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/
    Thomas Hawtin, Apr 14, 2006
    #4
  5. z-man

    z-man Guest

    Re: FATAL ERROR: could not compile stylesheet

    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 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"/>
    ....
    z-man, Apr 14, 2006
    #5
  6. z-man

    z-man Guest

    On 04/14/2006 09:56 AM, Thomas Hawtin wrote:
    > z-man wrote:
    >> 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)

    >
    > 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/XALANJ-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
    z-man, Apr 14, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    561
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. cvissy
    Replies:
    0
    Views:
    599
    cvissy
    Nov 16, 2004
  3. Steven An
    Replies:
    1
    Views:
    490
    Martin Honnen
    Nov 23, 2004
  4. David Blickstein
    Replies:
    3
    Views:
    1,024
    David Blickstein
    Aug 2, 2005
  5. vinnuavc
    Replies:
    0
    Views:
    1,792
    vinnuavc
    Jul 25, 2008
Loading...

Share This Page