Bug 194387: Support setting xslt parameters when transforming using a PI. r/sr/a=peterv
git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@198114 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -96,6 +96,7 @@
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsIDOMProcessingInstruction.h"
|
||||
|
||||
#ifdef MOZ_SVG
|
||||
#include "nsSVGAtoms.h"
|
||||
@@ -230,6 +231,50 @@ nsXMLContentSink::MaybePrettyPrint()
|
||||
return printer->PrettyPrint(mDocument);
|
||||
}
|
||||
|
||||
static void
|
||||
CheckXSLTParamPI(nsIDOMProcessingInstruction* aPi,
|
||||
nsIDocumentTransformer* aProcessor,
|
||||
nsIDocument* aDocument)
|
||||
{
|
||||
nsAutoString target, data;
|
||||
aPi->GetTarget(target);
|
||||
|
||||
nsCOMPtr<nsIDocumentTransformer_1_8_BRANCH> proc = do_QueryInterface(aProcessor);
|
||||
|
||||
// Check for namespace declarations
|
||||
if (target.EqualsLiteral("xslt-param-namespace")) {
|
||||
aPi->GetData(data);
|
||||
nsAutoString prefix, namespaceAttr;
|
||||
nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::prefix,
|
||||
prefix);
|
||||
if (!prefix.IsEmpty() &&
|
||||
nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::_namespace,
|
||||
namespaceAttr)) {
|
||||
proc->AddXSLTParamNamespace(prefix, namespaceAttr);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for actual parameters
|
||||
else if (target.EqualsLiteral("xslt-param")) {
|
||||
aPi->GetData(data);
|
||||
nsAutoString name, namespaceAttr, select, value;
|
||||
nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::name,
|
||||
name);
|
||||
nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::_namespace,
|
||||
namespaceAttr);
|
||||
if (!nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::select, select)) {
|
||||
select.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
if (!nsParserUtils::GetQuotedAttributeValue(data, nsHTMLAtoms::value, value)) {
|
||||
value.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
if (!name.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMNode> doc = do_QueryInterface(aDocument);
|
||||
proc->AddXSLTParam(name, namespaceAttr, select, value, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::DidBuildModel()
|
||||
{
|
||||
@@ -239,6 +284,21 @@ nsXMLContentSink::DidBuildModel()
|
||||
}
|
||||
|
||||
if (mXSLTProcessor) {
|
||||
|
||||
// Check for xslt-param and xslt-param-namespace PIs
|
||||
PRUint32 i;
|
||||
nsIContent* child;
|
||||
for (i = 0; (child = mDocument->GetChildAt(i)); ++i) {
|
||||
if (child->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) {
|
||||
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(child);
|
||||
CheckXSLTParamPI(pi, mXSLTProcessor, mDocument);
|
||||
}
|
||||
else if (child->IsContentOfType(nsIContent::eELEMENT)) {
|
||||
// Only honor PIs in the prolog
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> currentDOMDoc(do_QueryInterface(mDocument));
|
||||
mXSLTProcessor->SetSourceContentModel(currentDOMDoc);
|
||||
// Since the processor now holds a reference to us we drop our reference
|
||||
|
||||
Reference in New Issue
Block a user