Subject:Java extension functions, Xalan version in Stylus Studio? Author:Arcanum Development Date:08 Aug 2013 04:24 AM
Java extension functions to be developed for processing NodeList-s.
Primary attempts failed with exceptions, not even possible to retrieve the node type from Java.
Seemingly the objects passed are NodeLists, but Nodes cannot be accessed.
Also failed to use
org.w3c.dom.traversal.NodeIterator
as suggested, the function signature did not meet.
The passed class, indeed, is DTMAxisIterNodeList
which should be NodeList in principle, but functions return exceptions.
public class TraverseList
{
static{
System.out.println("hello");
};
public static String traverseList(NodeList nl)
{
String s = "NodeList:";
int l = nl.getLength();
for(int i=0;i<l;i++){
Node n = nl.item(i);
s += n.getNodeName()+":"+n.getNodeType()+";";
}
return s;
}
public static String traverseObject(Object o)
{
String s = o.getClass().getName();
return "ObjectClass:"+s+":";
}
public static String traverse(DocumentFragment df)
{
String s = "DocumentFragment:";
NodeList nl = df.getChildNodes();
int l = nl.getLength();
for(int i=0;i<l;i++){
Node n = nl.item(i);
s += n.getNodeName()+":"+n.getNodeType()+";";
}
return s;
}
}
Investigations pointed out, that node lists derived from the original source document cause no problems.
Exception dropped for traverse:traverseList(exslt:node-set($indirect)):
java.lang.ArrayIndexOutOfBoundsException: -1
at com.sun.org.apache.xml.internal.utils.SuballocatedIntVector.elementAt(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._exptype(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase.getNodeType(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl.getNodeName(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy.getNodeName(Unknown Source)
at test.TraverseList.traverseList(TraverseList.java:20)
Notice in the stack-trace the error is thrown while accessing the node object
at com.sun.org.apache.xml.internal.utils.SuballocatedIntVector.elementAt(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._exptype(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase.getNodeType(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl.getNodeName(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy.getNodeName(Unknown Source)
This works
java:test.TraverseList.traverseList($indirect)
I did few additional experiments using Node but in some cases the processor it's passing a null object
public static String traverseNode(org.w3c.dom.Node n)