diff --git a/mozilla/extensions/transformiix/source/xslt/ProcessorState.cpp b/mozilla/extensions/transformiix/source/xslt/ProcessorState.cpp index 6af02d5793e..6ea3e3c99de 100644 --- a/mozilla/extensions/transformiix/source/xslt/ProcessorState.cpp +++ b/mozilla/extensions/transformiix/source/xslt/ProcessorState.cpp @@ -50,14 +50,14 @@ DHASH_WRAPPER(txLoadedDocumentsBase, txLoadedDocumentEntry, nsAString&) -txLoadedDocumentsHash::txLoadedDocumentsHash(Document* aSourceDocument, - Document* aStyleDocument) - : mSourceDocument(aSourceDocument), - mStyleDocument(aStyleDocument) +nsresult txLoadedDocumentsHash::init(Document* aSourceDocument, + Document* aStyleDocument) { - if (NS_FAILED(Init(8))) { - return; - } + nsresult rv = Init(8); + NS_ENSURE_SUCCESS(rv, rv); + + mSourceDocument = aSourceDocument; + mStyleDocument = aStyleDocument; if (mSourceDocument) { Add(mSourceDocument); @@ -122,22 +122,30 @@ Document* txLoadedDocumentsHash::Get(const nsAString& aURI) /** * Creates a new ProcessorState for the given XSL document **/ -ProcessorState::ProcessorState(Document* aSourceDocument, - Document* aXslDocument) +ProcessorState::ProcessorState(Node* aSourceNode, Document* aXslDocument) : mOutputHandler(0), mResultHandler(0), mOutputHandlerFactory(0), - mLoadedDocuments(aSourceDocument, aXslDocument), mXslKeys(MB_TRUE), mDecimalFormats(MB_TRUE), mEvalContext(0), mLocalVariables(0), mGlobalVariableValues(MB_TRUE), - mRTFDocument(0) + mRTFDocument(0), + mSourceNode(aSourceNode) { - NS_ASSERTION(aSourceDocument, "missing source document"); + NS_ASSERTION(aSourceNode, "missing source node"); NS_ASSERTION(aXslDocument, "missing xslt document"); + Document* sourceDoc; + if (mSourceNode->getNodeType() == Node::DOCUMENT_NODE) { + sourceDoc = (Document*)mSourceNode; + } + else { + sourceDoc = mSourceNode->getOwnerDocument(); + } + mLoadedDocuments.init(sourceDoc, aXslDocument); + /* turn object deletion on for some of the Maps (NamedMap) */ mExprHashes[SelectAttr].setOwnership(Map::eOwnsItems); mExprHashes[TestAttr].setOwnership(Map::eOwnsItems); @@ -1068,7 +1076,7 @@ nsresult ProcessorState::getVariable(PRInt32 aNamespace, nsIAtom* aLName, // Set up the state we have at the beginning of the transformation txVariableMap *oldVars = mLocalVariables; mLocalVariables = 0; - txSingleNodeContext evalContext(mLoadedDocuments.mSourceDocument, this); + txSingleNodeContext evalContext(mSourceNode, this); txIEvalContext* priorEC = setEvalContext(&evalContext); // Compute the variable value globVar->mFlags = GlobalVariableValue::evaluating; diff --git a/mozilla/extensions/transformiix/source/xslt/ProcessorState.h b/mozilla/extensions/transformiix/source/xslt/ProcessorState.h index 542b7af6e86..2682cddb229 100644 --- a/mozilla/extensions/transformiix/source/xslt/ProcessorState.h +++ b/mozilla/extensions/transformiix/source/xslt/ProcessorState.h @@ -62,8 +62,8 @@ DECL_DHASH_WRAPPER(txLoadedDocumentsBase, txLoadedDocumentEntry, nsAString&) class txLoadedDocumentsHash : public txLoadedDocumentsBase { public: - txLoadedDocumentsHash(Document* aSourceDocument, Document* aStyleDocument); ~txLoadedDocumentsHash(); + nsresult init(Document* aSourceDocument, Document* aStyleDocument); void Add(Document* aDocument); Document* Get(const nsAString& aURI); @@ -83,8 +83,7 @@ public: * Creates a new ProcessorState for the given XSL document * And result Document */ - ProcessorState(Document* aSourceDocument, - Document* aXslDocument); + ProcessorState(Node* aSourceNode, Document* aXslDocument); /** * Destroys this ProcessorState @@ -498,6 +497,11 @@ private: * Document used to create RTFs */ Document* mRTFDocument; + + /** + * Source-node where processing started + */ + Node* mSourceNode; }; /** diff --git a/mozilla/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp b/mozilla/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp index 5bbead47db2..61293db9ff6 100644 --- a/mozilla/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp +++ b/mozilla/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp @@ -281,12 +281,12 @@ txMozillaXSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. - ProcessorState ps(&sourceDocument, &xslDocument); + ProcessorState ps(sourceNode, &xslDocument); // XXX Need to add error observers // Set current txIEvalContext - txSingleNodeContext evalContext(&sourceDocument, &ps); + txSingleNodeContext evalContext(sourceNode, &ps); ps.setEvalContext(&evalContext); // Index templates and process top level xslt elements @@ -348,12 +348,12 @@ txMozillaXSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. - ProcessorState ps(&sourceDocument, &xslDocument); + ProcessorState ps(sourceNode, &xslDocument); // XXX Need to add error observers // Set current txIEvalContext - txSingleNodeContext evalContext(&sourceDocument, &ps); + txSingleNodeContext evalContext(sourceNode, &ps); ps.setEvalContext(&evalContext); // Index templates and process top level xslt elements @@ -444,12 +444,12 @@ txMozillaXSLTProcessor::TransformToDocument(nsIDOMNode *aSource, // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. - ProcessorState ps(&sourceDocument, &xslDocument); + ProcessorState ps(sourceNode, &xslDocument); // XXX Need to add error observers // Set current txIEvalContext - txSingleNodeContext evalContext(&sourceDocument, &ps); + txSingleNodeContext evalContext(sourceNode, &ps); ps.setEvalContext(&evalContext); // Index templates and process top level xslt elements @@ -512,12 +512,12 @@ txMozillaXSLTProcessor::TransformToFragment(nsIDOMNode *aSource, // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. - ProcessorState ps(&sourceDocument, &xslDocument); + ProcessorState ps(sourceNode, &xslDocument); // XXX Need to add error observers // Set current txIEvalContext - txSingleNodeContext evalContext(&sourceDocument, &ps); + txSingleNodeContext evalContext(sourceNode, &ps); ps.setEvalContext(&evalContext); // Index templates and process top level xslt elements