Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2003, 04:47 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create and return a nodeset in a javascript

I need a function to create and return a nodeset to a variable from within my XSLT.

here is a small example of what I intend to do

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:ja="http://mycode/js" extension-element-prefixes="js msxsl">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <msxsl:script language="JavaScript" implements-prefix="js">    
        <![CDATA[            
            function getnewnodes() { 
                var xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
                var str;
                ...
                xmlDoc.loadXML("<root>" + str + </root>");
                return xmlDoc;
            };
        ]]>
    </msxsl:script>

    <xsl:template match="/">
        ....
        <xsl:variable name ="results" select="js:getnewnodes()"/>
        ....
    </xsl:template>
</xsl:stylesheet>
 
Old October 16th, 2003, 06:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm not sure why you are doing this, why not just use node-set function?



--

Joe
 
Old October 16th, 2003, 07:37 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The sample does not describe what I am actually doing,
this is to complicated.

However, I can say this.
Every time I find a specific structure in my source file I need to run an extremely complicated algorythm on the array of values it holds.
The result of the algorythm is another array of values, which I need to slot into my output at different places.

As the source array is held in a nodeset i send the function the node-set and let the function get the separate values from it.

The problem is how do I return the array of results back to xsl?
I thought that sending it back as a node-set was the best idea.
But I can not get it to work

 
Old October 16th, 2003, 07:42 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You're right, it is complicated. I don't really understand but if you return it as a valid xml string then you could use the msxml:node-set function on that.



--

Joe
 
Old October 16th, 2003, 07:49 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I dont understand!

I think your saying that the function should return a string of the xmlDoc, something like
"<resultarray><index0>1</index0><index1>2</index1><index2>3</index2></resultarray>"

But then how do I use msxml:node-set on this?

 
Old October 16th, 2003, 08:10 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Something like:
Code:
<xsl:variable name="myDoc" select="msxml:node-set(js:getnewnodes())"/>
--

Joe
 
Old October 16th, 2003, 08:44 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I only get the string and not the node-set returned

I am using msxsl:node-set(), is this the same or not?



 
Old October 16th, 2003, 10:12 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, my typo. So now your getnewnodes looks like:
Code:
function getnewnodes()
{ 
                var str;
                ...
                return "<root>" + str + </root>";
};
Hope I've understood :)

--

Joe
 
Old October 17th, 2003, 05:48 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have now replaced the javascript function with the equivalent using xsl:variables, its a bit long but at least it works.
I still need some javascript functions for the some maths, but thats ok.
It keeps the javacode small.






Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick="javascript: return false" on vista gabrieldcr2 Javascript 2 June 4th, 2008 09:40 AM
Javascript Function return save in XSL Variable Vrokad XSLT 2 June 2nd, 2007 02:54 AM
Javascript return false won't stop post rstelma ASP.NET 1.0 and 1.1 Basics 9 March 16th, 2006 02:25 PM
how to return nodeset in template in xsl:variable alexshiell XSLT 3 March 18th, 2005 01:36 PM
create a new variable in javascript crmpicco Classic ASP Basics 2 February 2nd, 2005 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.