Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this with JavaScript (Windows Script Host will run it):</p> <pre><code>function xmlTransformAndSave(xml, xsl, saveXmlPath, saveEnableOverwrite) { // Transforms input XML and saves output to file, preserving encoding specified // by xsl:output encoding attribute. The method used resolves the issue of XSL // XML output forced to UTF-16 encoding the moment it becomes a string in // JavaScript (JavaScript strings are UTF-16). Note saveEnableOverwrite is an // optional parameter enabled by default. // Optional input parameter default value saveMode = typeof saveMode != 'undefined' ? saveMode : true; // Convert to stream saveToFile parameter (1 = create; 2 = overwrite) saveMode = saveMode = true ? 2 : 1; // Output object, a stream (to preserve output encoding set in XSL) var stream = WScript.createObject("ADODB.Stream"); stream.open(); stream.type = 1; // Transform and save to file xml.transformNodeToObject(xsl, stream); stream.saveToFile(saveXmlPath, saveMode); stream.close(); } </code></pre> <p>The xml and xsl parameters are DOMDocument objects with xml and xsl already loaded. For example, xsl can come from this function:</p> <pre><code>function getXsl(xslPath) { //Returns XSL loaded from xslPath supplied //Create DOM "xsl" for XSL, set DOM options, and load XSL file var xsl = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0"); xsl.async = false; xsl.resolveExternals = false; xsl.validateOnParse = false; xsl.load(xslPath); //Return xsl return xsl; } </code></pre> <p>Using this transform method, you can set XSL input parameters with a code like this:</p> <pre><code>function xslSetParam(xsl, paramName, paramValue) { // Sets parameter value in xsl (call before transform) // Requires XSL structure "xsl:stylesheet" (NOT "xsl:transform", and NOT "xslt:") // Select parameter to set var xslParam = xsl.selectSingleNode("/xsl:stylesheet/xsl:param[@name='" + paramName + "']"); // Set parameter value xslParam.setAttribute("select", paramValue); } </code></pre> <p>The output encoding you specify in your XSL will now be the output encoding of the file and specified in the XML declaration of the file as expected. So an output encoding like this in your XSL:</p> <pre><code>&lt;xsl:output method="xml" indent="yes" encoding="UTF-8"/&gt; </code></pre> <p>Will give you the desired output--like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload