Microsoft KB Archive/315717

= HOW TO: Disable Output Escaping in XML Style Sheet Transformations =

Article ID: 315717

Article Last Modified on 2/3/2004

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q315717





IN THIS TASK

 * SUMMARY
 * Requirements
 * Create an XML Document and an XSL Style Sheet
 * Use Windows Script to Execute the Style Sheet
 * Test the Procedure
 * Troubleshooting
 * REFERENCES



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

To guarantee that any XSL transformation output is a well-formed document, the angle bracket characters are transformed by default into &quot;<&quot; and &quot;>&quot; 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)> ]> back to the top

Requirements
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)

back to the top

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:    Chris   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=&quot;yes&quot; attribute in the first xsl:value-of tag: <?xml version=&quot;1.0&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>

<xsl:output method=&quot;xml&quot; omit-xml-declaration=&quot;yes&quot;/>

<xsl:template match=&quot;Employee&quot;>

<xsl:value-of disable-output-escaping=&quot;yes&quot; select=&quot;concat('&lt;!DOCTYPE StaffMember [',                          '&lt;!ELEMENT StaffMember (#PCDATA)&gt;',                           ']&gt;')&quot; /> <StaffMember> <xsl:value-of select=&quot;Name&quot;/> </StaffMember>

</xsl:template>

</xsl:stylesheet> </li> Save this file as Transform.xsl in the same folder as the XML document that you just created.</li></ol>

back to the top

Use Windows Script to Execute the Style Sheet
<ol>  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(&quot;MSXML2.DOMDocument&quot;) objSource.async = False objSource.load &quot;Source.xml&quot;

Set objTransform = CreateObject(&quot;MSXML2.DOMDocument&quot;) objTransform.async = False objTransform.load &quot;Transform.xsl&quot;

sResult = objSource.TransformNode(objTransform.documentElement)

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

back to the top

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

back to the top

Troubleshooting
Be careful when you use the disable-output-escaping attribute. If the generated 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.

back to the top

<div class="references_section">