[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Xalan javascript; createElement ?

Subject: Xalan javascript; createElement ?
From: Tom Myers <tommy@xxxxxxxxxxxxxx>
Date: Tue, 05 Jun 2001 19:39:31 -0400
javascript createelement
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.