[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bsf-discussion
Subject:    [bsf-discussion] Re: Using Xalan with JPython via BSF
From:       inigo () marketing ! net ! uk
Date:       2000-11-24 9:57:42
[Download RAW message or body]

I wrote:

> I'm trying to work out how to use Apache Xalan with JPython.
> Xalan uses BSF for its scripting.

and reported no success.

I've investigated the problem further, and my initial problem was due to
whitespace -
a JPython function declaration must begin at the left margin when included
in a <lsxlt:script> tag.

I added an element tag "testElement", and received the JPython error:

testElement(org.apache.xalan.xslt.XSLProcessorContext@7ddc31,org.apache.xalan.xslt.ElemExtensionCall@35282)
  ^
SyntaxError: Lexical error at line 1, column 54.  Encountered: "@" (64),
after : ""

The problem here is that Python doesn't allow the @ character to be used in
function arguments. Since the
"org.apache.xalan.xslt.XSLProcessorContext@7ddc31" it complains
about appeared to be the default Java Object.toString(), I tried adding
toString()
methods to both ElemExtensionCall and XSLProcessorContext.

and the error changed to a JPython Name error -
     NameError: org
where I'd changed the toString for XSLProcessorContext to return
"org.apache.xalan.xslt.XSLProcessorContext"

Interestingly, when I changed both toString() methods to return "123", then
the call to testElement succeeded, but the context and element were the
number 123, and obviously not too useful for retrieving document data.

A similar problem occurs when passing arguments to a function rather than
an element - anything is passed other than a number, then a JPython Name
error occurs.

My intuition is that the problem is somewhere in the BSF engine code for
passing Java objects to the JPython - but that is purely a guess.

I'll investigate further, but I'd be grateful for any pointers.



I'm using Xalan 1.2 (although I also tested with Xalan 2.0D01), JPython
1.1, and the BSF shipped with Xalan - I'm not sure how to check its version
number.

The Java I'm using is trivial... essentially it's
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
    processor.process(new XSLTInputSource("foo.xml"),
                      new XSLTInputSource("foo.xsl"),
                      new XSLTResultTarget(System.out));

This is the stylesheet I'm using:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:lxslt="http://xml.apache.org/xslt"
    extension-element-prefixes="corianderpy"  xmlns:corianderpy
="corianderpy">

<lxslt:component prefix="corianderpy" functions="doImport" elements
="testelement">
<lxslt:script lang="jpython">

# Note the indentation - the function declaration must be
# flush with the left margin
def testFunction(arg1):
    return arg1*2

def testElement(context,element):
    return "Hello"
</lxslt:script>
</lxslt:component>

  <xsl:template match="/">
    <xsl:value-of select="corianderpy:testFunction(2)"/>
    <corianderpy:testElement anattr="yes" />
  </xsl:template>
</xsl:stylesheet>


Inigo Surguy


- ----
To get off the bsf-discussion list, send a message containing the word
"unsubscribe" (in the body, not the subject) to
<bsf-discussion-Request@OSS.Software.IBM.Com>.

Send Majordomo commands to: <bsf-discussion-Request@OSS.Software.IBM.Com>
To contact a human:         <bsf-discussion-Owner@OSS.Software.IBM.Com>
To post to the list:        <bsf-discussion@OSS.Software.IBM.Com>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic