Subject:Crash while invoking Java Extension function that returns NodeList Author:John van Haandel Date:24 Jun 2005 06:09 AM
Hello,
Can anyone help me with the following problem.
Via an xslt map, I try to invoke a Java extension class. But Stylus Studio crashes while invoking the method of this class. Does anybody know what I'm doning wrong ?
Thanks
John van Haandel
I'm using Stylus Studio 6 XML Professional Edition Release 2
Framework version Build 287m
and JVM : 1.4.2_07-b05 Java HotSpot(TM) Client VM Sun Microsystems Inc.
I've written the following class:
import org.w3c.dom.*;
import javax.imageio.metadata.IIOMetadataNode;
public class TestValueMapping {
public TestValueMapping(){
}
public static Object returnNodeSet(String firstString, String secondString){
IIOMetadataNode retFrag = new IIOMetadataNode("John0001");
DocumentFragment df = null;
IIOMetadataNode myNode = new IIOMetadataNode(firstString);
IIOMetadataNode my2Node = new IIOMetadataNode(secondString);
myNode.setNodeValue(firstString);
retFrag.appendChild(myNode);
my2Node.setNodeValue(secondString);
retFrag.appendChild(my2Node);
Node realNode = (Node) retFrag.cloneNode(true);
return retFrag.getChildNodes();
I invoke the java extension class via the following lines in an XSLT mapping:
Subject:Crash while invoking Java Extension function that returns NodeList Author:Ivan Pedruzzi Date:24 Jun 2005 04:13 PM
John
The Stylus Studio built-in processor doesn't support creation of XML fragments. Even so it should not crash, the problem will be fixed in future update.
Still you can run your extension function using the XalanJ processor (click "..." -> processors -> XalanJ)
There are two additional problems:
1) Your XSLT is trying to insert nodes under an attribute which doesn't make sense. Change your code like this
2) the Java extension is trying to call setNodeVale on an Element that does nothing. setNodeVale only works on Text node.
In alternative you can use attributes like that:
public static Object returnNodeSet(String firstString, String secondString) throws ParserConfigurationException
{
IIOMetadataNode retFrag = new IIOMetadataNode("John0001");
IIOMetadataNode myNode = new IIOMetadataNode(firstString);
IIOMetadataNode my2Node = new IIOMetadataNode(secondString);
// Use Attributes instead
retFrag.setAttribute(firstString, firstString);
retFrag.setAttribute(secondString, secondString);
return retFrag;
}
Be carefull because as you can read from IIOMetadataNode javaDoc
<<"
This class is not intended to be used for general XML processing. In particular, Element nodes created within the Image I/O API are not compatible with those created by Sun's standard implementation of the org.w3.dom API. In particular, the implementation is tuned for simple uses and may not perform well for intensive processing.
">>