I'd better start by saying that I'm new to java, which is probably part of
the problem. I'm using xalan 2.1.0 and I'm switching between JDK 1.3 and
1.4 beta. I've tried to get this question as short as I can, but I'm afraid
its still rather large.
I'm been having serious trouble getting an extension to work which returns a
NodeIterator. Unfortunately there isn't a sample that actually does this.
I've written a small test object:
import org.w3c.dom.traversal.NodeIterator;
import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
public class Iterator implements NodeIterator {
private int mlngCount;
private org.w3c.dom.Document mobjDocument;
public Iterator() throws javax.xml.parsers.ParserConfigurationException {
DocumentBuilderFactory objFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder objBuilder = objFactory.newDocumentBuilder();
mobjDocument = objBuilder.newDocument();
}
public NodeIterator getNodeList() {
return this;
}
public Node getRoot() {
return mobjDocument;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
public NodeFilter getFilter() {
return null;
}
public boolean getExpandEntityReferences() {
return false;
}
public Node nextNode() throws DOMException {
mlngCount++;
if (mlngCount<10) {
org.w3c.dom.Element objElement = mobjDocument.createElement("Hello");
objElement.setAttribute("value", String.valueOf(mlngCount));
return objElement;
}
return null;
}
public Node previousNode() throws DOMException {
throw (new DOMException(DOMException.NOT_SUPPORTED_ERR, "This is a
custom iterator which cannot go back."));
}
public void detach() {
// Empty
}
}
and I'm using the following file to test it:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
version="1.0">
<xsl:template match="/">
<xsl:for-each select="java:getNodeList(java:Iterator.new())" />
</xsl:template>
</xsl:stylesheet>
as you can see, it doesn't really matter what xml file you use as long as
it's valid. I'm using the Xalan Process program to test the extension.
I've tried quite a number of different versions (using components, using
variables &c) and they all come back to the following output:
<?xml version="1.0" encoding="UTF-8"?>
XSLT Error (javax.xml.transform.TransformerException): Iterator
Now, stepping through the code I can see that this occurs in
org.apache.xalan.transformer.TransformerImpl. It has successfully called
the routines and converted the result to an XNodeSet and then proceeds to
blow up. I've been trying for several days now trying to track down exactly
why this happens but unfortunately, for reasons I don't understand, I've
been unable to view the local variables that would help me debug. I've even
modified the build.xml to show debug as on and rebuilt xalan (and copied it
to bin) and it hasn't helped.
So, my questions are:
i) What does the error message mean?
ii) What am I doing wrong?
iii) How do I fix it?
iv) Does anyone have an example of a custom NodeIterator that works?
v) How do I get Xalan compiled with variable information intact?
Thanks in advance,
Julian.
===========================================================================
The information in this E-mail (which includes any files transmitted with
it), is confidential and may also be legally privileged. It is intended for
the addressee only. Access to this E-mail by anyone else is unauthorised. If
you have received it in error, please destroy any copies and delete it from
your system notifying the sender immediately. Any use, dissemination,
forwarding, printing or copying of this E-mail is prohibited. E-mail
communications are not secure and therefore Rolfe & Nolan does not accept
legal responsibility for the contents of this message. Any views or opinions
presented are solely those of the author and do not necessarily represent
those of Rolfe & Nolan.
===========================================================================