Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 234631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:02+00:00 2026-05-11T20:12:02+00:00

I am trying to create a new XML file from an exisiting one using

  • 0

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.

This is how my XML looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Sumit>
    <AccountName>Sumit</AccountName>
      <CCT_datasetT id="Table">
       <row>
         <CCTTitle2>Title</CCTTitle2>
       </row>
       </CCT_datasetT>
</Sumit>

Here is my XSL Code:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />

  <xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

  <xsl:template match="@*">
    <xsl:attribute namespace="{namespace-uri()}" name="{name()}"/>
  </xsl:template>

<xsl:template match="AccountName">
<AccountName>acc_no</AccountName>
</xsl:template>

</xsl:stylesheet>

When I apply the XSL code to my XML, I get the following output:

<?xml version="1.0" encoding="UTF-16"?>
<Sumit>
<AccountName>acc_no</AccountName>
<CCT_datasetT id="">
<row>
<CCTTitle2>Title</CCTTitle2>
</row>
</CCT_datasetT>
</Sumit>

with the following issues:

1) It creates the output using UTF-16 encoding

2) The output of the second line is:

<CCT_datasetT id="">

The attribute value(Table) is missing.

Can anyone please tell me how do I get rid of these two issues. Many thanks.


@Evan Lenz:

Here is the javascript 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();

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:

My input XML containg the following code:

<Status></Status>

And in the output it appears as

<Status>
</Section>

A carriage return is introduced for all empty tags. I am not sure, if it has something to do with the encoding. Please suggest.

Many Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:12:02+00:00Added an answer on May 11, 2026 at 8:12 pm

    Remove your second template rule. The first template rule (the identity rule) will already copy attributes for you. By including the second one (which has the explicit <xsl:attribute> instruction), you’re creating a conflict–an error condition, and the XSLT processor is recovering by picking the one that comes later in your stylesheet. The reason the “id” attribute is empty is that your second rule is creating a new attribute with the same name but with no value. But again, that second rule is unnecessary anyway, so you should just delete it. That will solve the missing attribute value issue.

    As for the output encoding, it sounds like your XSLT processor is not honoring the <xsl:output> directive you’ve given it, or it’s being invoked in a context (such as a server-side framework?) where the encoding is determined by the framework, rather than the XSLT code. What XSLT processor are you using and how are you invoking it?

    UPDATE (re: character encoding):

    The save Method (DOMDocument) documentation says this:

    Character encoding is based on the encoding attribute in the XML declaration, such as <?xml version="1.0" encoding="windows-1252"?>. When no encoding attribute is specified, the default setting is UTF-8.

    I would try using transformNodeToObject() and save() instead of outputting to a string.

    I haven’t tested this, but you probably want something like this:

    var result = new ActiveXObject("Microsoft.XMLDOM")
    
    // Transform
    xml.transformNodeToObject(xsl, result);
    
    result.save("Output.xml");
    

    UPDATE (re: unwanted whitespace):

    If you want to have ultimate control over what whitespace appears in the result, you should not specify indent=”yes” on the <xsl:output> element. Try removing that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Create a new SubClass of ImageIcon and ovveride the method… May 11, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer Are the Facade objects both the same in the test… May 11, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer What you want to do is create: List<Word> words =… May 11, 2026 at 9:15 pm

Related Questions

I have a piece of data. At the moment, it's an XML file, but
Here's a quick question I've been banging my head against today. I'm trying to
I am trying to use symbolic links in one of the applications I have
I'm new to JQuery and web development in general. I'm trying to load some
I recently wrote a DLL in C# (.Net 2.0) which contains a class that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.