From 37844fba4bfc20675ee79ce5adc1c5231d14ae0f Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Tue, 18 Jul 2006 11:44:31 +0000 Subject: [PATCH] Fix for bug 344362 (xsl:output omit-xml-declaration="no" does not create an XML declaration). r/sr=sicking. --- content/xslt/src/xslt/txMozillaXMLOutput.cpp | 20 ++++++++++++++++++++ content/xslt/src/xslt/txXMLOutput.cpp | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.cpp b/content/xslt/src/xslt/txMozillaXMLOutput.cpp index cd7333c2a779..53fde4bda1ca 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp +++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp @@ -831,6 +831,26 @@ txMozillaXMLOutput::createResultDocument(const nsAString& aName, PRInt32 aNsID, doc->SetContentType(NS_LITERAL_STRING("application/xml")); } + if (mOutputFormat.mMethod == eXMLOutput && + mOutputFormat.mOmitXMLDeclaration != eTrue) { + PRInt32 standalone; + if (mOutputFormat.mStandalone == eNotSet) { + standalone = -1; + } + else if (mOutputFormat.mStandalone == eFalse) { + standalone = 0; + } + else { + standalone = 1; + } + + // Could use mOutputFormat.mVersion.get() when we support + // versions > 1.0. + static const PRUnichar kOneDotZero[] = { '1', '.', '0', '\0' }; + doc->SetXMLDeclaration(kOneDotZero, mOutputFormat.mEncoding.get(), + standalone); + } + // Set up script loader of the result document. nsIScriptLoader *loader = doc->GetScriptLoader(); if (loader) { diff --git a/content/xslt/src/xslt/txXMLOutput.cpp b/content/xslt/src/xslt/txXMLOutput.cpp index 96fc57a69c66..d654e9f43793 100644 --- a/content/xslt/src/xslt/txXMLOutput.cpp +++ b/content/xslt/src/xslt/txXMLOutput.cpp @@ -212,9 +212,18 @@ void txXMLOutput::startDocument() // XXX We should "cache" content until we have a // document element } - *mOut << PI_START << XML_DECL << DOUBLE_QUOTE; - *mOut << XML_VERSION; - *mOut << DOUBLE_QUOTE << " encoding=\"UTF-8\"" << PI_END << endl; + if (mOutputFormat.mMethod == eXMLOutput && + mOutputFormat.mOmitXMLDeclaration != eTrue) { + *mOut << PI_START << XML_DECL << DOUBLE_QUOTE; + *mOut << XML_VERSION; + *mOut << DOUBLE_QUOTE << " encoding=\"UTF-8\""; + if (mOutputFormat.mStandalone != eNotSet) { + *mOut << " standalone=\""; + *mOut << (mOutputFormat.mStandalone == eFalse ? "no" : "yes") << "\""; + } + *mOut << PI_END << endl; + + } } void txXMLOutput::startElement(const nsAString& aName,