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
- Open a text editor such as Notepad, and then paste the following XML in a document:
<?xml-stylesheet type="text/xsl" href="Transform.xsl"?>
- Save this file as Source.xml.
- 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:
<xsl:output method="xml" omit-xml-declaration="yes"/>
select="concat('<!DOCTYPE StaffMember [',
'<!ELEMENT StaffMember (#PCDATA)>',
- 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
- Create a new file in your text editor, and then paste the following script in the file:
Set objSource = CreateObject("MSXML2.DOMDocument")
objSource.async = False
Set objTransform = CreateObject("MSXML2.DOMDocument")
objTransform.async = False
sResult = objSource.TransformNode(objTransform.documentElement)
- 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
- Open a command prompt, and then locate the folder that contains your three files.
- Type cscript xform.vbs at the command prompt.
- 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
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:
Determine the Version of MSXML Parser Installed on a Computer
Article ID: 315717 - Last Review: June 22, 2014 - Revision: 3.0
|kbhowto kbhowtomaster KB315717|