dbertoni 2002/07/09 22:09:49
Modified: c/src/XSLT ElemApplyTemplates.cpp ElemForEach.cpp
ElemForEach.hpp ElemTemplateElement.cpp
ElemTemplateElement.hpp ElemVariable.hpp
ElemWithParam.hpp
Log:
Moved transformSelectedChildren() into ElemForEach, since that's the only
place it's used.
Revision Changes Path
1.23 +9 -11 xml-xalan/c/src/XSLT/ElemApplyTemplates.cpp
Index: ElemApplyTemplates.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemApplyTemplates.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ElemApplyTemplates.cpp 23 Feb 2002 04:23:16 -0000 1.22
+++ ElemApplyTemplates.cpp 10 Jul 2002 05:09:48 -0000 1.23
@@ -156,7 +156,14 @@
XalanNode* const sourceNode = executionContext.getCurrentNode();
- if (0 != sourceNode)
+ if (sourceNode == 0)
+ {
+ executionContext.error(
+ "There is no current node in
ElemApplyTemplates::execute()",
+ sourceNode,
+ this);
+ }
+ else
{
// Dragons here. Push the params & stack frame, but then
execute the
// select statement inside transformSelectedChildren, which
must be
@@ -168,9 +175,8 @@
sourceNode,
this);
- assert(executionContext.getCurrentMode() != 0);
-
const XalanQName* const currentMode =
executionContext.getCurrentMode();
+ assert(currentMode != 0);
if (m_isDefaultTemplate == false &&
!m_mode.equals(*currentMode))
@@ -194,13 +200,6 @@
thePushPop.getStackFrameIndex());
}
}
- else
- {
- executionContext.error(
- "There is no current node in
ElemApplyTemplates::execute()",
- sourceNode,
- this);
- }
}
@@ -212,7 +211,6 @@
switch(xslToken)
{
- // char-instructions
case Constants::ELEMNAME_SORT:
case Constants::ELEMNAME_WITHPARAM:
fResult = true;
1.25 +155 -15 xml-xalan/c/src/XSLT/ElemForEach.cpp
Index: ElemForEach.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemForEach.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ElemForEach.cpp 29 May 2002 18:21:52 -0000 1.24
+++ ElemForEach.cpp 10 Jul 2002 05:09:48 -0000 1.25
@@ -75,8 +75,13 @@
+#include <XPath/XPath.hpp>
+
+
+
#include "ElemSort.hpp"
#include "NodeSorter.hpp"
+#include "SelectionEvent.hpp"
#include "StylesheetConstructionContext.hpp"
#include "StylesheetExecutionContext.hpp"
@@ -93,7 +98,9 @@
lineNumber,
columnNumber,
Constants::ELEMNAME_FOREACH),
- m_selectPattern(0)
+ m_selectPattern(0),
+ m_sortElems(),
+ m_sortElemsCount(0)
{
const unsigned int nAttrs = atts.getLength();
@@ -137,7 +144,9 @@
lineNumber,
columnNumber,
xslToken),
- m_selectPattern(0)
+ m_selectPattern(0),
+ m_sortElems(),
+ m_sortElemsCount(0)
{
}
@@ -165,6 +174,18 @@
void
+ElemForEach::postConstruction(
+ StylesheetConstructionContext& constructionContext,
+ const NamespacesHandler&
theParentHandler)
+{
+ ElemTemplateElement::postConstruction(constructionContext,
theParentHandler);
+
+ m_sortElemsCount = m_sortElems.size();
+}
+
+
+
+void
ElemForEach::execute(StylesheetExecutionContext& executionContext) const
{
assert(m_selectPattern != 0);
@@ -186,7 +207,7 @@
else
{
executionContext.error(
- "There is no current node in
ElemForEach::execute()!",
+ "There is no current node in
ElemForEach::execute()",
sourceNode,
this);
}
@@ -202,17 +223,15 @@
XalanNode*
sourceNodeContext,
int
selectStackFrameIndex) const
{
- const SortElemsVectorType& sortElements =
getSortElems();
- const SortElemsVectorType::size_type nChildren = sortElements.size();
+ assert(m_selectPattern != 0);
+ assert(m_sortElemsCount == m_sortElems.size());
- if (nChildren == 0)
+ if (m_sortElemsCount == 0)
{
- ElemTemplateElement::transformSelectedChildren(
+ transformSelectedChildren(
executionContext,
- *this,
theTemplate,
sourceNodeContext,
- *m_selectPattern,
0,
selectStackFrameIndex);
}
@@ -229,7 +248,7 @@
CollectionClearGuard<NodeSortKeyVectorType>
guard(keys);
// Reserve the space now...
- keys.reserve(nChildren);
+ keys.reserve(m_sortElemsCount);
// Get some temporary strings to use for evaluting the AVTs...
XPathExecutionContext::GetAndReleaseCachedString
theTemp1(executionContext);
@@ -242,9 +261,9 @@
// March backwards, performing a sort on each xsl:sort child.
// Probably not the most efficient method.
- for(SortElemsVectorType::size_type i = 0; i < nChildren;
i++)
+ for(SortElemsVectorType::size_type i = 0; i <
m_sortElemsCount; i++)
{
- const ElemSort* const sort = sortElements[i];
+ const ElemSort* const sort = m_sortElems[i];
assert(sort != 0);
const AVT* avt = sort->getLangAVT();
@@ -361,13 +380,134 @@
*this));
}
- ElemTemplateElement::transformSelectedChildren(
+ transformSelectedChildren(
executionContext,
- *this,
theTemplate,
sourceNodeContext,
- *m_selectPattern,
sorter.get(),
selectStackFrameIndex);
+ }
+}
+
+
+
+void
+ElemForEach::transformSelectedChildren(
+ StylesheetExecutionContext&
executionContext,
+ const ElemTemplateElement* theTemplate,
+ XalanNode*
sourceNodeContext,
+ NodeSorter*
sorter,
+ int
selectStackFrameIndex) const
+{
+ typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex
SetAndRestoreCurrentStackFrameIndex;
+
+ assert(m_selectPattern != 0);
+
+ XObjectPtr theXObject;
+
+ {
+ SetAndRestoreCurrentStackFrameIndex
theSetAndRestore(
+ executionContext,
+ selectStackFrameIndex);
+
+ theXObject = m_selectPattern->execute(
+ sourceNodeContext,
+ *this,
+ executionContext);
+ }
+
+ if (theXObject.null() == false)
+ {
+ const NodeRefListBase& sourceNodes = theXObject->nodeset();
+
+ if(0 != executionContext.getTraceListeners())
+ {
+ executionContext.fireSelectEvent(
+ SelectionEvent(executionContext,
+ sourceNodeContext,
+ *this,
+
StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("select")),
+ *m_selectPattern,
+ theXObject));
+ }
+
+ const NodeRefListBase::size_type nNodes =
sourceNodes.getLength();
+
+ if (nNodes > 0)
+ {
+ // If there's not NodeSorter, or we've only selected
one node,
+ // then just do the transform...
+ if (sorter == 0 || nNodes == 1)
+ {
+ transformSelectedChildren(
+ executionContext,
+ theTemplate,
+ sourceNodes,
+ nNodes);
+ }
+ else
+ {
+ typedef
StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex
SetAndRestoreCurrentStackFrameIndex;
+ typedef
StylesheetExecutionContext::ContextNodeListSetAndRestore
ContextNodeListSetAndRestore;
+ typedef
StylesheetExecutionContext::BorrowReturnMutableNodeRefList
BorrowReturnMutableNodeRefList;
+
+ BorrowReturnMutableNodeRefList
sortedSourceNodes(executionContext);
+
+ *sortedSourceNodes = sourceNodes;
+
+ {
+ SetAndRestoreCurrentStackFrameIndex
theStackFrameSetAndRestore(
+ executionContext,
+ selectStackFrameIndex);
+
+ ContextNodeListSetAndRestore
theContextNodeListSetAndRestore(
+ executionContext,
+ sourceNodes);
+
+ sorter->sort(executionContext,
*sortedSourceNodes);
+ }
+
+ transformSelectedChildren(
+ executionContext,
+ theTemplate,
+ *sortedSourceNodes,
+ nNodes);
+ }
+ }
+ }
+}
+
+
+
+void
+ElemForEach::transformSelectedChildren(
+ StylesheetExecutionContext&
executionContext,
+ const ElemTemplateElement* theTemplate,
+ const NodeRefListBase& sourceNodes,
+ NodeRefListBase::size_type
sourceNodesCount) const
+{
+ if(executionContext.getTraceSelects() == true)
+ {
+ executionContext.traceSelect(
+ *this,
+ sourceNodes,
+ m_selectPattern);
+ }
+
+ // Create an object to set and restore the context node list...
+ StylesheetExecutionContext::ContextNodeListSetAndRestore
theSetAndRestore(
+ executionContext,
+ sourceNodes);
+
+ for(unsigned int i = 0; i < sourceNodesCount; i++)
+ {
+ XalanNode* const childNode = sourceNodes.item(i);
+ assert(childNode != 0);
+
+ transformChild(
+ executionContext,
+ *this,
+ theTemplate,
+ childNode);
}
}
1.14 +56 -1 xml-xalan/c/src/XSLT/ElemForEach.hpp
Index: ElemForEach.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemForEach.hpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ElemForEach.hpp 26 Sep 2001 21:30:23 -0000 1.13
+++ ElemForEach.hpp 10 Jul 2002 05:09:48 -0000 1.14
@@ -70,11 +70,20 @@
// Base class header file.
#include "ElemTemplateElement.hpp"
+
+
+
+#include <XPath/NodeRefListBase.hpp>
+
+
+
#include "Constants.hpp"
class ElemSort;
+class ElemTemplate;
+class NodeSorter;
class XPath;
@@ -121,12 +130,23 @@
return m_sortElems;
}
+ const XPath*
+ getSelectExpression() const
+ {
+ return m_selectPattern;
+ }
+
// These methods are inherited from ElemTemplateElement ...
virtual const XalanDOMString&
getElementName() const;
virtual void
+ postConstruction(
+ StylesheetConstructionContext& constructionContext,
+ const NamespacesHandler&
theParentHandler);
+
+ virtual void
execute(StylesheetExecutionContext& executionContext) const;
protected:
@@ -163,11 +183,46 @@
XalanNode*
sourceNodeContext,
int
selectStackFrameIndex) const;
+ /**
+ * Perform a query if needed, and call transformChild for each child.
+ *
+ * @param executionContext The current execution context
+ * @param template The owning template context.
+ * @param sourceNodeContext The current source node context.
+ * @param selectStackFrameIndex stack frame context for executing the
+ * select
statement
+ */
+ void
+ transformSelectedChildren(
+ StylesheetExecutionContext& executionContext,
+ const ElemTemplateElement* theTemplate,
+ XalanNode*
sourceNodeContext,
+ NodeSorter* sorter,
+ int
selectStackFrameIndex) const;
+
+ /**
+ * Perform a query if needed, and call transformChild for each child.
+ *
+ * @param executionContext The current execution context
+ * @param theTemplate The owning template context.
+ * @param sourceNodes The source nodes to transform.
+ * @param sourceNodesCount The count of source nodes to transform.
+ */
+ void
+ transformSelectedChildren(
+ StylesheetExecutionContext& executionContext,
+ const ElemTemplateElement* theTemplate,
+ const NodeRefListBase& sourceNodes,
+ NodeRefListBase::size_type
sourceNodesCount) const;
+
const XPath* m_selectPattern;
private:
- SortElemsVectorType m_sortElems;
+ SortElemsVectorType m_sortElems;
+
+ SortElemsVectorType::size_type m_sortElemsCount;
+
};
1.75 +1 -126 xml-xalan/c/src/XSLT/ElemTemplateElement.cpp
Index: ElemTemplateElement.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- ElemTemplateElement.cpp 10 Jul 2002 00:42:36 -0000 1.74
+++ ElemTemplateElement.cpp 10 Jul 2002 05:09:48 -0000 1.75
@@ -95,6 +95,7 @@
#include "Constants.hpp"
#include "ElemCallTemplate.hpp"
+#include "ElemForEach.hpp"
#include "ElemTemplate.hpp"
#include "NamespacesHandler.hpp"
#include "NodeSorter.hpp"
@@ -670,132 +671,6 @@
oldChild->setNextSiblingElem(0);
return oldChild;
-}
-
-
-
-void
-ElemTemplateElement::transformSelectedChildren(
- StylesheetExecutionContext&
executionContext,
- const ElemTemplateElement& xslInstruction,
- const ElemTemplateElement* theTemplate,
- XalanNode*
sourceNodeContext,
- const XPath&
selectPattern,
- NodeSorter*
sorter,
- int
selectStackFrameIndex) const
-{
- typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex
SetAndRestoreCurrentStackFrameIndex;
-
- XObjectPtr theXObject;
-
- {
- SetAndRestoreCurrentStackFrameIndex
theSetAndRestore(
- executionContext,
- selectStackFrameIndex);
-
- theXObject = selectPattern.execute(
- sourceNodeContext,
- xslInstruction,
- executionContext);
- }
-
- if (theXObject.null() == false)
- {
- const NodeRefListBase& sourceNodes = theXObject->nodeset();
-
- if(0 != executionContext.getTraceListeners())
- {
- executionContext.fireSelectEvent(
- SelectionEvent(executionContext,
- sourceNodeContext,
- *this,
-
StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("select")),
- selectPattern,
- theXObject));
- }
-
- const NodeRefListBase::size_type nNodes =
sourceNodes.getLength();
-
- if (nNodes > 0)
- {
- // If there's not NodeSorter, or we've only selected
one node,
- // then just do the transform...
- if (sorter == 0 || nNodes == 1)
- {
- transformSelectedChildren(
- executionContext,
- xslInstruction,
- theTemplate,
- sourceNodes,
- nNodes);
- }
- else
- {
- typedef
StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex
SetAndRestoreCurrentStackFrameIndex;
- typedef
StylesheetExecutionContext::ContextNodeListSetAndRestore
ContextNodeListSetAndRestore;
- typedef
StylesheetExecutionContext::BorrowReturnMutableNodeRefList
BorrowReturnMutableNodeRefList;
-
- BorrowReturnMutableNodeRefList
sortedSourceNodes(executionContext);
-
- *sortedSourceNodes = sourceNodes;
-
- {
- SetAndRestoreCurrentStackFrameIndex
theStackFrameSetAndRestore(
- executionContext,
- selectStackFrameIndex);
-
- ContextNodeListSetAndRestore
theContextNodeListSetAndRestore(
- executionContext,
- sourceNodes);
-
- sorter->sort(executionContext,
*sortedSourceNodes);
- }
-
- transformSelectedChildren(
- executionContext,
- xslInstruction,
- theTemplate,
- *sortedSourceNodes,
- nNodes);
- }
- }
- }
-}
-
-
-
-void
-ElemTemplateElement::transformSelectedChildren(
- StylesheetExecutionContext&
executionContext,
- const ElemTemplateElement&
xslInstruction,
- const ElemTemplateElement*
theTemplate,
- const NodeRefListBase&
sourceNodes,
- NodeRefListBase::size_type
sourceNodesCount) const
-{
- if(executionContext.getTraceSelects() == true)
- {
- executionContext.traceSelect(
- xslInstruction,
- sourceNodes,
- 0);
- }
-
- // Create an object to set and restore the context node list...
- StylesheetExecutionContext::ContextNodeListSetAndRestore
theSetAndRestore(
- executionContext,
- sourceNodes);
-
- for(unsigned int i = 0; i < sourceNodesCount; i++)
- {
- XalanNode* const childNode = sourceNodes.item(i);
- assert(childNode != 0);
-
- transformChild(
- executionContext,
- xslInstruction,
- theTemplate,
- childNode);
- }
}
1.43 +0 -45 xml-xalan/c/src/XSLT/ElemTemplateElement.hpp
Index: ElemTemplateElement.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.hpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- ElemTemplateElement.hpp 10 Jul 2002 00:42:36 -0000 1.42
+++ ElemTemplateElement.hpp 10 Jul 2002 05:09:48 -0000 1.43
@@ -82,10 +82,6 @@
-#include <XPath/NodeRefListBase.hpp>
-
-
-
#include <XSLT/NamespacesHandler.hpp>
@@ -93,11 +89,9 @@
class AttributeList;
class ElemTemplate;
class NamespacesHandler;
-class NodeSorter;
class Stylesheet;
class StylesheetConstructionContext;
class StylesheetExecutionContext;
-class XPath;
@@ -729,45 +723,6 @@
*/
const XalanDOMString*
getNamespaceForPrefixInternal(const XalanDOMString& prefix) const;
-
- /**
- * Perform a query if needed, and call transformChild for each child.
- *
- * @param executionContext The current execution context
- * @param xslInstruction The stylesheet element context (deprecated --
I do
- * not think we need this).
- * @param template The owning template context.
- * @param sourceNodeContext The current source node context.
- * @param selectPattern The XPath with which to perform the selection.
- * @param selectStackFrameIndex stack frame context for executing the
- * select
statement
- */
- void
- transformSelectedChildren(
- StylesheetExecutionContext& executionContext,
- const ElemTemplateElement& xslInstruction,
- const ElemTemplateElement* theTemplate,
- XalanNode*
sourceNodeContext,
- const XPath&
selectPattern,
- NodeSorter* sorter,
- int
selectStackFrameIndex) const;
-
- /**
- * Perform a query if needed, and call transformChild for each child.
- *
- * @param executionContext The current execution context
- * @param xslInstruction The stylesheet element context
- * @param theTemplate The owning template context.
- * @param sourceNodes The source nodes to transform.
- * @param sourceNodesCount The count of source nodes to transform.
- */
- void
- transformSelectedChildren(
- StylesheetExecutionContext&
executionContext,
- const ElemTemplateElement&
xslInstruction,
- const ElemTemplateElement*
theTemplate,
- const NodeRefListBase&
sourceNodes,
- NodeRefListBase::size_type
sourceNodesCount) const;
/**
* Given an element, find the corresponding
1.16 +5 -1 xml-xalan/c/src/XSLT/ElemVariable.hpp
Index: ElemVariable.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemVariable.hpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ElemVariable.hpp 13 Aug 2001 17:08:53 -0000 1.15
+++ ElemVariable.hpp 10 Jul 2002 05:09:48 -0000 1.16
@@ -83,6 +83,10 @@
+class XPath;
+
+
+
class ElemVariable : public ElemTemplateElement
{
public:
1.9 +4 -0 xml-xalan/c/src/XSLT/ElemWithParam.hpp
Index: ElemWithParam.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemWithParam.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ElemWithParam.hpp 13 Aug 2001 17:08:53 -0000 1.8
+++ ElemWithParam.hpp 10 Jul 2002 05:09:48 -0000 1.9
@@ -73,6 +73,10 @@
+class XPath;
+
+
+
class ElemWithParam : public ElemTemplateElement
{
public:
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]