Ignore the typo in the sample stylesheet - the <A> element is properly
closed </A> in the real thing...

-----Original Message-----
From: Rick Bullotta [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 13, 2001 9:58 AM
To: Xalan
Subject: Xalan D13/Extension Function Issue?


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>


Reply via email to