This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Xalan javascript; createElement ?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] Xalan javascript; createElement ?
- From: Tom Myers <tommy at cs dot colgate dot edu>
- Date: Tue, 05 Jun 2001 19:39:31 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
Should I be able to return the result of a javascript
"createElement" into a result tree within Xalan? At the
moment I'm just exploring...here's where I am:
Starting with Michael Kay's (2nd Ed p.813) sample of
javascript extension functions to Xalan, or with the
Xalan sample code with the distribution, I have little
trouble writing a silly javascript DOM function to use within
XPath e.g.
<xsl:value-of select="user:up($someNode)"/>
or even
<xsl:copy-of select="user:up($someNode)"/>
where my script defines
function up(nodeList){
var node=nodeList.item(0);
var mom=node.getParentNode();
return mom;
}
So I can return existing subtrees of the source document tree
(or in the stylesheet document tree, for that matter). Similarly
getAttribute and so on work fine. In the document tree I can
even create new elements as in the nonsense-function
function up(nodeList){
var node=nodeList.item(0);
var mom=node.getParentNode();
var doc=mom.getOwnerDocument();
var elt=doc.createElement("h2");
elt.appendChild(doc.createTextNode("gerbil"));
node.appendChild(elt);
return elt.getFirstChild().getNodeValue();
}
and this produces the expected value ("gerbil"), but you
notice that I am not returning the actual computed element.
If I try to return "elt", or even if I try to return "node"
after the appendChild(elt), the process hangs.
I can remove the "node.appendChild(..)" and then return "node",
no problem, but I can't return a new element. If I try to
create new elements in the stylesheet tree the process doesn't
hang; it blows up, which seems reasonable, but I'd like to know
if there is a way to construct and return new elements. Does
anybody know?
BTW, the code above comes not from examining existing examples
or javascript documentation; I started with
function up(nodeList){return nodeList.toString();}
and found that the result included the name of the class I was
working with, which supports getLength() and item(int i). If
there is a collection of relevant examples/documentation, I'd
like to know.
Ideally, I'd like to do this within a javascript SOAP service
in Apache SOAP, where I don't know of any starting XML document
even though the javascript lives in a DeploymentDescriptor.xml
and is Rhino javascript run by BSF, just as this is...so it might
be possible. But for now I'd be very happy if somebody could
point me to what I should be reading, or just tell me that the
functionality I'm trying for is/isn't possible...
Tom Myers
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list