tags:

views:

48

answers:

1

I have an XSLT transform I am using to process an XML file, inserting it into the body of my aspx page.

Reference the following for background information:

background on xml/xslt

I have the following in my xml file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:myCustomStrings="urn:customStrings">
  <xsl:output
    method="xml" version="2.0"
    media-type="text/html"
    omit-xml-declaration="yes"
    indent="yes"
 />...unrelated stuff left out here

Here is the output that is relevent:

<div id="example" />
    <?xml version="1.0" encoding="utf-8"?><div xmlns:myCustomStrings="urn:customStrings"><div id="imFormBody" class="imFormBody">

My question relates to the output, specifically to the <?xml version="1.0" encoding="utf-8"?> which is getting included in the output anyway. Is the issue related to the custom method I have used? If so, I don't really see the need to include the xml part as the namespace is in the div tag. Is there a way to ensure that this extra stuff gets left out as I asked it to?

transform code: yeah, its ugly but I am prototyping some stuff :)

public static string SmartNotePageFromTemplate(string patientVisitId, string followupType, bool copyPreviousNote)
    {
        // create custom object
        CustomStrings customStrings = new CustomStrings();//specify class for use in XSLT

        string noteXmlFile = ImSmartNotesConfig.GetSmartNotesXmlFile();//get xml data file name from config
        string noteXslFile = ImSmartNotesConfig.GetSmartNotesXsltFile();// get xslt file name from config

        string subXmlFile = "../SmartNotesXml/testData.xml";
        string subCSSFile = "../CSS/testCSS.css";
        string subJSFile = "../Js/testJS.js";

        try
        {
            XsltSettings settings = new XsltSettings(true, true);// allow the document() in the xslt

            XsltArgumentList xslArg = new XsltArgumentList();// create argument list for xslt
            xslArg.AddParam("subXmlFile", "", subXmlFile);
            xslArg.AddParam("subCSSFile", "", subCSSFile);
            xslArg.AddParam("subJSFile", "", subJSFile);
            //pass an instance of the custom object
            xslArg.AddExtensionObject("urn:customStrings", customStrings);

            XslCompiledTransform myXslt = new XslCompiledTransform(true);// we will use the compiled xslt processor
            myXslt.Load(noteXslFile, settings, new XmlUrlResolver());// load the xslt in
            StringWriter stWrite = new StringWriter();// create output writer

            //myXslt.Transform(noteXmlFile, xslArg, stWrite);// transform 
            SmartNote.BL.SmartNoteLogic logic = new SmartNote.BL.SmartNoteLogic();
            XmlDocument noteXml = logic.GetNewNoteXml(patientVisitId, followupType, copyPreviousNote);
            myXslt.Transform(noteXml, xslArg, stWrite);// transform 

            return stWrite.ToString();// put the StringWriter as a string to the output- html page in this instance, as used in the .aspx.cs file
        }
        catch (Exception e)
        {
            throw e;
        }
    }
A: 

As it turns out this was as a result of the method server side where I did the transform.

It did not matter what the XSLT said as the .net method overrode that.

I ended up with the following code snip in my c# code:

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
Mark Schultheiss