HOW TO: Disable Output Escaping in XML Style Sheet Transformations


This step-by-step article describes how to disable output escaping of characters such as < and > in an XML style sheet transformation.

To guarantee that any XSL transformation output is a well-formed document, the angle bracket characters (< and >) are transformed by default into "<" and ">" character sequences. However, sometimes this behavior is not desirable, such as when you want to generate a Document Type Declaration (DTD) in the output document:

<!DOCTYPE StaffMember [
<!ELEMENT StaffMember (#PCDATA)>


The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:

  • Microsoft XML version 3.0 or later
This article assumes that you are familiar with the following topics:

  • XML and XSL transformations and the MSXML component
  • Visual Basic Scripting Edition (VBScript)
  • XML Document Object Model (DOM)

Create an XML Document and an XSL Style Sheet

  1. Open a text editor such as Notepad, and then paste the following XML in a document:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="Transform.xsl"?>
  2. Save this file as Source.xml.
  3. Create a new file in your text editor, and then paste the following XSL style sheet in the file. Notice the disable-output-escaping="yes" attribute in the first xsl:value-of tag:
    <?xml version="1.0"?>

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:template match="Employee">

    select="concat('&lt;!DOCTYPE StaffMember [',
    '&lt;!ELEMENT StaffMember (#PCDATA)&gt;',
    ']&gt;')" />

    <xsl:value-of select="Name"/>


  4. Save this file as Transform.xsl in the same folder as the XML document that you just created.

Use Windows Script to Execute the Style Sheet

  1. Create a new file in your text editor, and then paste the following script in the file:
    Option Explicit

    Dim objSource
    Dim objTransform
    Dim sResult

    Set objSource = CreateObject("MSXML2.DOMDocument")
    objSource.async = False
    objSource.load "Source.xml"

    Set objTransform = CreateObject("MSXML2.DOMDocument")
    objTransform.async = False
    objTransform.load "Transform.xsl"

    sResult = objSource.TransformNode(objTransform.documentElement)

    WScript.Echo sResult
  2. Save this file as Xform.vbs in the same folder as the XML document and the XSL style sheet that you just created.

Test the Procedure

  1. Open a command prompt, and then locate the folder that contains your three files.
  2. Type cscript xform.vbs at the command prompt.
  3. The output from the transformation is displayed as follows on the screen:
    <!DOCTYPE StaffMember [<!ELEMENT StaffMember (#PCDATA)>]>


Be careful when you use the disable-output-escaping attribute. If the generated < and > characters do not match up, the output document will not be well-formed XML. The transformNodeToObject method requires the result to be well-formed, so the method might not complete if disable-output-escaping is used.


For additional information about how to determine the version of MSXML that is installed on your computer, click the article number below to view the article in the Microsoft Knowledge Base:

278674 Determine the Version of MSXML Parser Installed on a Computer

ID articol: 315717 - Ultima examinare: 22 iun. 2014 - Revizie: 1