Note that there are some explanatory texts on larger screens.

plurals
  1. POXML to XML using XSLT
    primarykey
    data
    text
    <p>I am trying to create a new XML file from an exisiting one using XSL. When writing the new file, I want to mask data appearing in the accountname field.</p> <p><strong>This is how my XML looks like:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Sumit&gt; &lt;AccountName&gt;Sumit&lt;/AccountName&gt; &lt;CCT_datasetT id="Table"&gt; &lt;row&gt; &lt;CCTTitle2&gt;Title&lt;/CCTTitle2&gt; &lt;/row&gt; &lt;/CCT_datasetT&gt; &lt;/Sumit&gt; </code></pre> <p><strong>Here is my XSL Code:</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no" /&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*"&gt; &lt;xsl:attribute namespace="{namespace-uri()}" name="{name()}"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="AccountName"&gt; &lt;AccountName&gt;acc_no&lt;/AccountName&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When I apply the XSL code to my XML, I get the following output: </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-16"?&gt; &lt;Sumit&gt; &lt;AccountName&gt;acc_no&lt;/AccountName&gt; &lt;CCT_datasetT id=""&gt; &lt;row&gt; &lt;CCTTitle2&gt;Title&lt;/CCTTitle2&gt; &lt;/row&gt; &lt;/CCT_datasetT&gt; &lt;/Sumit&gt; </code></pre> <p>with the following issues:</p> <p>1) It creates the output using UTF-16 encoding</p> <p>2) The output of the second line is:</p> <pre><code>&lt;CCT_datasetT id=""&gt; </code></pre> <p>The attribute value(Table) is missing.</p> <p>Can anyone please tell me how do I get rid of these two issues. Many thanks.</p> <hr> <p>@Evan Lenz:</p> <p>Here is the javascript code:</p> <pre><code>var oArgs = WScript.Arguments; if (oArgs.length == 0) { WScript.Echo ("Usage : cscript xslt.js xml xsl"); WScript.Quit(); } xmlFile = oArgs(0) + ".xml"; xslFile = oArgs(1) + ".xsl"; var xml = new ActiveXObject("Microsoft.XMLDOM") xml.async = false xml.load(xmlFile) // Load the XSL var xsl = new ActiveXObject("Microsoft.XMLDOM") xsl.async = false xsl.load(xslFile) // Transform var msg = xml.transformNode(xsl) var fso = new ActiveXObject("Scripting.FileSystemObject"); // Open the text file at the specified location with write mode var txtFile = fso.OpenTextFile("Output.xml", 2, false, 0); txtFile.Write(msg); txtFile.close(); </code></pre> <p>It creates the output in a new file "Output.xml", but I don't know why the encoding is getting changed. I am more concerned about it, because of the following reason:</p> <p>My input XML containg the following code:</p> <pre><code>&lt;Status&gt;&lt;/Status&gt; </code></pre> <p>And in the output it appears as</p> <pre><code>&lt;Status&gt; &lt;/Section&gt; </code></pre> <p>A carriage return is introduced for all empty tags. I am not sure, if it has something to do with the encoding. Please suggest.</p> <p>Many Thanks.</p>
    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.
 

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