You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Kariann Butler <kb...@rxremedy.com> on 2001/01/02 16:16:58 UTC
Xalan-Java extensions
Hello,
I have a couple of comments regarding the available documentation on
using the Xalan-Java extensions
(http://xml.apache.org/xalan-j/extensions.html). I wrote an extension
using Java. At first, I did not include the bsf.jar file because of
this statement, "BSF requires bsf.jar on the class path. This JAR file
is shipped with Xalan-Java and is required only if you have extensions
written in languages other than Java." (This is under the section,
"Supported languages".) I had to include that file anyway because until
I did, I was getting a NoClassDefFound error.
Also, I was using the package format namespace to work with my
extension. To declare the namespace, I followed the instructions under
the section,"Alternative: using the abbreviated syntax for extensions
implemented in Java." They are a little confusing. When I was working
on this, I was under the impression I had to have the xalan:// prefix.
My extensions were not found until I removed the prefix.
Re: Xalan-Java extensions
Posted by Gary L Peskin <ga...@firstech.com>.
> > Kariann Butler wrote:
> >
> >> I have a couple of comments regarding the available documentation on
> >> using the Xalan-Java extensions
> >> (http://xml.apache.org/xalan-j/extensions.html). I wrote an extension
> >> using Java. At first, I did not include the bsf.jar file because of
> >> this statement, "BSF requires bsf.jar on the class path. This JAR file
> >> is shipped with Xalan-Java and is required only if you have extensions
> >> written in languages other than Java." (This is under the section,
> >> "Supported languages".) I had to include that file anyway because until
> >> I did, I was getting a NoClassDefFound error.
> >>
> >> Also, I was using the package format namespace to work with my
> >> extension. To declare the namespace, I followed the instructions under
> >> the section,"Alternative: using the abbreviated syntax for extensions
> >> implemented in Java." They are a little confusing. When I was working
> >> on this, I was under the impression I had to have the xalan:// prefix.
> >> My extensions were not found until I removed the prefix.
>
> Hello Gary,
>
> Here is a simplified version of the stylesheet and the code. The actual
> works are proprietary, so I could not include the entire files.
> However, what I have given here is everything related to calling the
> extension.
>
> Karianne
>
> ----------------------------------------------------------------------------
> The Java extension code
>
> package feed;
>
> import java.util.*;
> import java.io.*;
>
> public class StripNewLines {
>
> public StripNewLines() {
> }
>
> public String strip(String inStr) {
> String outStr;
>
> outStr = inStr.replace('\n', ' ');
>
> return outStr;
> }
>
> }
> -----------------------------------------------------------------------------
> The style sheet
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0"
> xmlns:stripnl="feed.StripNewLines">
> <!-- the above line is where I originally had
> xmlns:stripnl="xalan://feed.StripNewLines"> -->
>
> <xsl:output
> method = "text"
> indent = "no"
> />
>
> <xsl:template match="FEED">
> <xsl:apply-templates select="ARTICLE"/>
> </xsl:template>
>
> <xsl:template match="ARTICLE">
> <xsl:text>
> </xsl:text>
> <xsl:text>ARTICLE_ID:</xsl:text><xsl:value-of select="@ID"/>
> <xsl:text>
> </xsl:text>
>
> <xsl:apply-templates select="BODY" />
> </xsl:template>
>
> <xsl:template match="ARTICLE/BODY">
>
> <xsl:variable name="body"
> select="string(.)"/>
>
> <xsl:variable name="stripper"
> select="stripnl:new()"/>
>
> <xsl:text>BODY:</xsl:text>
> <xsl:value-of select="stripnl:strip($stripper, $body)"/>
> <xsl:text>
> </xsl:text>
> </xsl:template>
> </xsl:stylesheet>
Kariann --
I just tried your XSLT and java code with the following input XML:
<?xml version="1.0" encoding="UTF-8"?>
<FEED>
<ARTICLE ID="id1">
<BODY>
This is a test of the article body.
That was a new line and
here is another.
</BODY>
</ARTICLE>
</FEED>
and it worked perfectly with the xalan://feed.StripNewLines namespace
URI. I did not have bsf.jar in my classpath.
The symptoms that you're describing make it seem to me like you might be
running XalanJ1. Please check your classpath and make sure that you're
actually running the XalanJ2 jar. You can verify the version also by
specifying the -v switch on the command line.
Also, I'm not sure if your actual extension function is preserving any
state information in member fields. If not, you can make your "strip"
function static and invoke it like this:
<xsl:template match="ARTICLE/BODY">
<xsl:text>BODY:</xsl:text>
<xsl:value-of select="stripnl:strip(string(.))"/>
<xsl:text>
</xsl:text>
</xsl:template>
which is a little more compact.
Gary
Re: Xalan-Java extensions
Posted by Kariann Butler <kb...@rxremedy.com>.
Gary L Peskin wrote:
> Kariann Butler wrote:
>
>> I have a couple of comments regarding the available documentation on
>> using the Xalan-Java extensions
>> (http://xml.apache.org/xalan-j/extensions.html). I wrote an extension
>> using Java. At first, I did not include the bsf.jar file because of
>> this statement, "BSF requires bsf.jar on the class path. This JAR file
>> is shipped with Xalan-Java and is required only if you have extensions
>> written in languages other than Java." (This is under the section,
>> "Supported languages".) I had to include that file anyway because until
>> I did, I was getting a NoClassDefFound error.
>>
>> Also, I was using the package format namespace to work with my
>> extension. To declare the namespace, I followed the instructions under
>> the section,"Alternative: using the abbreviated syntax for extensions
>> implemented in Java." They are a little confusing. When I was working
>> on this, I was under the impression I had to have the xalan:// prefix.
>> My extensions were not found until I removed the prefix.
>
>
> Kariann --
>
> Thank you for your feedback. We will use it to improve the
> documentation. Can you please for a copy of the XSLT stylesheet that
> you are using as well as the Java extension code so that we can see
> exactly what you're talking about?
>
> Thanks,
> Gary
>
Hello Gary,
Here is a simplified version of the stylesheet and the code. The actual
works are proprietary, so I could not include the entire files.
However, what I have given here is everything related to calling the
extension.
Karianne
----------------------------------------------------------------------------
The Java extension code
package feed;
import java.util.*;
import java.io.*;
public class StripNewLines {
public StripNewLines() {
}
public String strip(String inStr) {
String outStr;
outStr = inStr.replace('\n', ' ');
return outStr;
}
}
-----------------------------------------------------------------------------
The style sheet
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:stripnl="feed.StripNewLines">
<!-- the above line is where I originally had
xmlns:stripnl="xalan://feed.StripNewLines"> -->
<xsl:output
method = "text"
indent = "no"
/>
<xsl:template match="FEED">
<xsl:apply-templates select="ARTICLE"/>
</xsl:template>
<xsl:template match="ARTICLE">
<xsl:text>
</xsl:text>
<xsl:text>ARTICLE_ID:</xsl:text><xsl:value-of select="@ID"/>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="BODY" />
</xsl:template>
<xsl:template match="ARTICLE/BODY">
<xsl:variable name="body"
select="string(.)"/>
<xsl:variable name="stripper"
select="stripnl:new()"/>
<xsl:text>BODY:</xsl:text>
<xsl:value-of select="stripnl:strip($stripper, $body)"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
Re: Xalan-Java extensions
Posted by Gary L Peskin <ga...@firstech.com>.
Kariann Butler wrote:
> I have a couple of comments regarding the available documentation on
> using the Xalan-Java extensions
> (http://xml.apache.org/xalan-j/extensions.html). I wrote an extension
> using Java. At first, I did not include the bsf.jar file because of
> this statement, "BSF requires bsf.jar on the class path. This JAR file
> is shipped with Xalan-Java and is required only if you have extensions
> written in languages other than Java." (This is under the section,
> "Supported languages".) I had to include that file anyway because until
> I did, I was getting a NoClassDefFound error.
>
> Also, I was using the package format namespace to work with my
> extension. To declare the namespace, I followed the instructions under
> the section,"Alternative: using the abbreviated syntax for extensions
> implemented in Java." They are a little confusing. When I was working
> on this, I was under the impression I had to have the xalan:// prefix.
> My extensions were not found until I removed the prefix.
Kariann --
Thank you for your feedback. We will use it to improve the
documentation. Can you please for a copy of the XSLT stylesheet that
you are using as well as the Java extension code so that we can see
exactly what you're talking about?
Thanks,
Gary