xsl-list
[Top] [All Lists]

Re: [xsl] writing to file from MSXML 4.0

2008-06-06 06:41:59


--------------------------------------------------
From: "Christian Wittern" <cwittern(_at_)gmail(_dot_)com>
Sent: Friday, June 06, 2008 2:10 PM
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: Re: [xsl] writing to file from MSXML 4.0

Dear Joe,

Thanks for the quick answer.

Chris

Basically you use transformNodeToObject, there's an example here:
http://msdn.microsoft.com/en-us/library/ms766561(VS.85).aspx
If your output is XML then use the same logic as the example except
instead of the last line (WScript.echo) use result.save(<path to >
save to>).
If the output is not XML you can use an ADODB.Stream instead of a
DomDocument to accept the result and write to disk.

I guess you are talking about this example:


// Load data.
var source = new ActiveXObject("Msxml2.DOMDocument.3.0");
source.async = false;
source.load("hello.xml");
if (source.parseError.errorCode != 0) {
  var myErr = source.parseError;
  WScript.Echo("You have error " + myErr.reason);
} else {
  // Load style sheet.
  var stylesheet = new ActiveXObject("Msxml2.DOMDocument.3.0");
  stylesheet.async = false;
  stylesheet.load("hello.xsl");
  if (stylesheet.parseError.errorCode != 0) {
     var myErr = stylesheet.parseError;
     WScript.Echo("You have error " + myErr.reason);
  } else {
     // Set up the resulting document.
     var result = new ActiveXObject("Msxml2.DOMDocument.3.0");
     result.async = false;
     result.validateOnParse = true;
     // Parse results into a result DOM Document.
     WScript.Echo(source.transformNodeToObject(stylesheet, result));
  }
}

Unfortunately, this is doing the reverse, calling a XSL transform from
Jscript. What I need is calling JScript from XSLT.
The following is the closest I found to what I need:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
     xmlns:user="http://mycompany.com/mynamespace";>

<msxsl:script language="JScript" implements-prefix="user">
  function xml(nodelist) {
     return nodelist.nextNode().xml;
  }
</msxsl:script>

<xsl:template match="/">
  <xsl:value-of select="user:xml(.)"/>
</xsl:template>

</xsl:stylesheet>

However what I do not understand is, how to get an object that can be
saved in the msxsl:script block.

All the best,

Chris


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


Chris

You're right, I misunderstood.
In the script block you need to create a new DomDocument and load the XML. Then call the save method.
function saveNodes(nodelist)
{
 var oDom = new ActiveXObject("MSXML2.DomDocument.4.0");
 oDom.loadXML("<root/>");
 for (var i = 0, l = nodelist.length; i < l; i++)
 {
     var node = nodelist[i];
    oDom.documentElement.appendChild(node.cloneNode(true));
 }
 oDom.save("myFolder/myFile.xml");
}

Joe
http://joe.fawcett.name

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>