You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Rick Bullotta <ri...@lighthammer.com> on 2001/11/13 15:57:57 UTC

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>


RE: Xalan D13/Extension Function Issue? DTM getChildNodes bug?

Posted by Rick Bullotta <ri...@lighthammer.com>.
Some more detail:

To get this working, we toyed with developing our own "deep cloning" API
that would get around this issue.  However, in the process, we discovered
what may be a serious bug in the DTMNodeProxy implementation.  Given a
document that looks like:

		<A>
			<B>3</B>
			<C>A</C>
		</A>

Calling getChildNodes() on the <A> element node returns two nodes.  However,
item(0) and item(1) have the same name and value (equivalent to the first
node).  They appear, however, to be different object references (see below
trace output).

[Tue Nov 13 11:14:12 COT 2001] Child Node 0 was
org.apache.xml.dtm.ref.DTMNodeProxy@472d48
[Tue Nov 13 11:14:12 COT 2001] Element Node 0 was B
[Tue Nov 13 11:14:12 COT 2001] Child Node 1 was
org.apache.xml.dtm.ref.DTMNodeProxy@6df3f6
[Tue Nov 13 11:14:12 COT 2001] Element Node 1 was B

Your thoughts?

- Rick

-----Original Message-----
From: Rick Bullotta [mailto:rick.bullotta@lighthammer.com]
Sent: Tuesday, November 13, 2001 10:07 AM
To: xalan-dev@xml.apache.org
Subject: RE: Xalan D13/Extension Function Issue?


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

-----Original Message-----
From: Rick Bullotta [mailto:rick.bullotta@lighthammer.com]
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>




RE: Xalan D13/Extension Function Issue?

Posted by Rick Bullotta <ri...@lighthammer.com>.
Ignore the typo in the sample stylesheet - the <A> element is properly
closed </A> in the real thing...

-----Original Message-----
From: Rick Bullotta [mailto:rick.bullotta@lighthammer.com]
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>