When is a Node not a node? That is the question... <g>
Here's the deal:
In an extension function, we're building a DOM based on values and NodeLists
passed to the extension function. The problem we face, however, is that a
node passed in a nodelist using 2.2 D13 blows up
(org.apache.xml.dtm.DTMDOMException) when a call to importNode is made as
shown below...
Anything you can point us to relative to problems with importNode in the
DTM/DOM implementation?
Here's a snippet/pseudocode and stripped down stylesheet to explain (this is
dramatically simplified from the real thing, which does a number of complex
calculations in the extension function, but isolates the problematic section
of code):
Rick Bullotta
CTO
Lighthammer Software (www.lighthammer.com)
=========================
**** CODE ****
public static NodeList DoTheThing(String sRequestID, NodeList nl) {
Document lDoc = null;
Element eRoot = null;
try {
lDoc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
eRoot = lDoc.createElement( "TheRoot" );
eRoot.setAttribute("Request",sRequestID);
lDoc.appendChild(eRoot);
// Graft the passed in node
Node nItem = lDoc.importNode(nl.item(0),true); // <===== Goes BOOM
here
// Note: nl.item(0) is a valid node - we have dumped it out to
the console via a serializer to verify
return lDoc.getChildNodes();
}
catch (Exception e) {
System.out.println(e);
}
return null;
}
**** STYLESHEET ****
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:java="http://xml.apache.org/xslt/java"
xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan
java">
<xsl:output method="xml" media-type="text/xml"/>
<xsl:param name="RequestID">1</xsl:param>
<xsl:template match="/">
<xsl:variable name="Info">
<A>
<B>3</B>
<C>A</C>
<A>
</xsl:variable>
<!-- Use the Java extension function to parse/populate the datavalues
elements -->
<xsl:copy-of select="java:LHSPC.DoTheThing($RequestID, $Info)"/>
</xsl:template>
</xsl:stylesheet>
BEGIN:VCARD
VERSION:2.1
N:Bullotta;Rick
FN:Rick Bullotta
ORG:Lighthammer Software Development Corporation
TITLE:Vice President/CTO
TEL;WORK;VOICE:(610) 903-8000 x14
TEL;WORK;FAX:(610) 903-8006
ADR;WORK:;;690 Stockton Drive, Suite 112;Exton;PA;19341;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:690 Stockton Drive, Suite 112=0D=0AExton, PA 19341=0D=0AUnited States of Ame=
rica
URL;WORK:http://www.lighthammer.com
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20011108T213540Z
END:VCARD