Refactored the internal structures into specialized structures and
authorKasimier T. Buchcik <kbuchcik@src.gnome.org>
Wed, 12 Apr 2006 11:42:32 +0000 (11:42 +0000)
committerKasimier T. Buchcik <kbuchcik@src.gnome.org>
Wed, 12 Apr 2006 11:42:32 +0000 (11:42 +0000)
* libxslt/attributes.c libxslt/preproc.c libxslt/transform.c
  libxslt/variables.c libxslt/xslt.c libxslt/xsltInternals.h
  libxslt/xsltutils.c libxslt/xsltutils.h:
  Refactored the internal structures into specialized
  structures and adjusted the code to work with those new
  structures. I didn't yet (we should in the future)
  renamed any fields of the old structures in order to avoid
  changing too much code.
  Introduced the internal structure xsltCompilerCtxt to be
  used for storage and control of the compilation.
  Optimized the way lists of in-scope namespaces are created
  and stored; this will now only generate a new list if
  really needed, i.e. if we encounter a ns-decl.
  All this changes here are IFDEFed out with XSLT_REFACTORED.

ChangeLog
libxslt/attributes.c
libxslt/preproc.c
libxslt/transform.c
libxslt/variables.c
libxslt/xslt.c
libxslt/xsltInternals.h
libxslt/xsltutils.c
libxslt/xsltutils.h

index 78604f7..cbe9ae8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Wed Apr 12 13:35:45 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
+
+       * libxslt/attributes.c libxslt/preproc.c libxslt/transform.c
+         libxslt/variables.c libxslt/xslt.c libxslt/xsltInternals.h
+         libxslt/xsltutils.c libxslt/xsltutils.h:
+         Refactored the internal structures into specialized
+         structures and adjusted the code to work with those new
+         structures. I didn't yet (we should in the future)
+         renamed any fields of the old structures in order to avoid
+         changing too much code.
+         Introduced the internal structure xsltCompilerCtxt to be
+         used for storage and control of the compilation.
+         Optimized the way lists of in-scope namespaces are created
+         and stored; this will now only generate a new list if
+         really needed, i.e. if we encounter a ns-decl.
+         All this changes here are IFDEFed out with XSLT_REFACTORED.
+         
 Thu Apr  6 10:16:59 CEST 2006 Daniel Veillard <daniel@veillard.com>
 
        * doc/xsltproc.1 doc/xsltproc.xml: applied man page improvement
index c6869ec..9e6dbb4 100644 (file)
@@ -565,9 +565,15 @@ xsltResolveStylesheetAttributeSet(xsltStylesheetPtr style) {
  */
 static void
 xsltAttributeInternal(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                      xmlNodePtr inst, xsltStylePreCompPtr comp,
-                      int fromset)
-{
+                      xmlNodePtr inst,
+                     xsltStylePreCompPtr castedComp,
+                      int fromset) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemAttributePtr comp =
+       (xsltStyleItemAttributePtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlChar *prop = NULL;
     xmlChar *namespace;
     const xmlChar *name = NULL;
index 936146c..899c5fa 100644 (file)
@@ -211,15 +211,91 @@ xsltCheckParentElement(xsltStylesheetPtr style, xmlNodePtr inst,
  *
  * Create a new XSLT Style precomputed block
  *
- * Returns the newly allocated xsltStylePreCompPtr or NULL in case of error
+ * Returns the newly allocated specialized structure
+ *         or NULL in case of error
  */
 static xsltStylePreCompPtr
 xsltNewStylePreComp(xsltStylesheetPtr style, xsltStyleType type) {
     xsltStylePreCompPtr cur;
+#ifdef XSLT_REFACTORED
+    size_t size;
+#endif
 
     if (style == NULL)
         return(NULL);
+   
+#ifdef XSLT_REFACTORED
+    /*
+    * URGENT TODO: Use specialized factory functions in order
+    *   to avoid this ugliness.
+    */
+    switch (type) {
+        case XSLT_FUNC_COPY:
+            size = sizeof(xsltStyleItemCopy); break;
+        case XSLT_FUNC_SORT:
+            size = sizeof(xsltStyleItemSort); break;
+        case XSLT_FUNC_TEXT:
+            size = sizeof(xsltStyleItemText); break;
+        case XSLT_FUNC_ELEMENT:
+            size = sizeof(xsltStyleItemElement); break;
+        case XSLT_FUNC_ATTRIBUTE:
+            size = sizeof(xsltStyleItemAttribute); break;
+        case XSLT_FUNC_COMMENT:
+            size = sizeof(xsltStyleItemComment); break;
+        case XSLT_FUNC_PI:
+            size = sizeof(xsltStyleItemPI); break;
+        case XSLT_FUNC_COPYOF:
+            size = sizeof(xsltStyleItemCopyOf); break;
+        case XSLT_FUNC_VALUEOF:
+            size = sizeof(xsltStyleItemValueOf); break;;
+        case XSLT_FUNC_NUMBER:
+            size = sizeof(xsltStyleItemNumber); break;
+        case XSLT_FUNC_APPLYIMPORTS:
+            size = sizeof(xsltStyleItemApplyImports); break;
+        case XSLT_FUNC_CALLTEMPLATE:
+            size = sizeof(xsltStyleItemCallTemplate); break;
+        case XSLT_FUNC_APPLYTEMPLATES:
+            size = sizeof(xsltStyleItemApplyTemplates); break;
+        case XSLT_FUNC_CHOOSE:
+            size = sizeof(xsltStyleItemChoose); break;
+        case XSLT_FUNC_IF:
+            size = sizeof(xsltStyleItemIf); break;
+        case XSLT_FUNC_FOREACH:
+            size = sizeof(xsltStyleItemForEach); break;
+        case XSLT_FUNC_DOCUMENT:
+            size = sizeof(xsltStyleItemDocument); break;
+       case XSLT_FUNC_WITHPARAM:
+           size = sizeof(xsltStyleItemWithParam); break;
+       case XSLT_FUNC_PARAM:
+           size = sizeof(xsltStyleItemParam); break;
+       case XSLT_FUNC_VARIABLE:
+           size = sizeof(xsltStyleItemVariable); break;
+       case XSLT_FUNC_WHEN:
+           size = sizeof(xsltStyleItemWhen); break;
+       case XSLT_FUNC_OTHERWISE:
+           size = sizeof(xsltStyleItemOtherwise); break;
+       default:        
+           xsltTransformError(NULL, style, NULL,
+                   "xsltNewStylePreComp : invalid type %d\n", type);
+           style->errors++;
+           return(NULL);
+    }
+    /*
+    * Create the structure.
+    */
+    cur = (xsltStylePreCompPtr) xmlMalloc(size);
+    if (cur == NULL) {
+       xsltTransformError(NULL, style, NULL,
+               "xsltNewStylePreComp : malloc failed\n");
+       style->errors++;
+       return(NULL);
+    }
+    memset(cur, 0, size);
 
+#else /* XSLT_REFACTORED */
+    /*
+    * Old behaviour.
+    */
     cur = (xsltStylePreCompPtr) xmlMalloc(sizeof(xsltStylePreComp));
     if (cur == NULL) {
        xsltTransformError(NULL, style, NULL,
@@ -228,7 +304,11 @@ xsltNewStylePreComp(xsltStylesheetPtr style, xsltStyleType type) {
        return(NULL);
     }
     memset(cur, 0, sizeof(xsltStylePreComp));
+#endif /* XSLT_REFACTORED */
 
+    /*
+    * URGENT TODO: Better to move this to spezialized factory functions.
+    */
     cur->type = type;
     switch (cur->type) {
         case XSLT_FUNC_COPY:
@@ -267,13 +347,11 @@ xsltNewStylePreComp(xsltStylesheetPtr style, xsltStyleType type) {
         case XSLT_FUNC_DOCUMENT:
             cur->func = (xsltTransformFunction) xsltDocumentElem;break;
        case XSLT_FUNC_WITHPARAM:
-           cur->func = NULL;break;
-       case XSLT_FUNC_PARAM:
-           cur->func = NULL;break;
-       case XSLT_FUNC_VARIABLE:
-           cur->func = NULL;break;
+       case XSLT_FUNC_PARAM:       
+       case XSLT_FUNC_VARIABLE:            
        case XSLT_FUNC_WHEN:
-           cur->func = NULL;break;
+       case XSLT_FUNC_OTHERWISE:
+           break;
        default:
        if (cur->func == NULL) {
            xsltTransformError(NULL, style, NULL,
@@ -297,11 +375,111 @@ static void
 xsltFreeStylePreComp(xsltStylePreCompPtr comp) {
     if (comp == NULL)
        return;
-
+#ifdef XSLT_REFACTORED
+    /*
+    * URGENT TODO: Implement destructors.
+    */
+    switch (comp->type) {
+       case XSLT_FUNC_COPY:
+            break;
+        case XSLT_FUNC_SORT: {
+               xsltStyleItemSortPtr item = (xsltStyleItemSortPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_TEXT:
+            break;
+        case XSLT_FUNC_ELEMENT:
+            break;
+        case XSLT_FUNC_ATTRIBUTE:
+            break;
+        case XSLT_FUNC_COMMENT:
+            break;
+        case XSLT_FUNC_PI:
+           break;
+        case XSLT_FUNC_COPYOF: {
+               xsltStyleItemCopyOfPtr item = (xsltStyleItemCopyOfPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_VALUEOF: {
+               xsltStyleItemValueOfPtr item = (xsltStyleItemValueOfPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_NUMBER:
+            break;
+        case XSLT_FUNC_APPLYIMPORTS:
+            break;
+        case XSLT_FUNC_CALLTEMPLATE:
+            break;
+        case XSLT_FUNC_APPLYTEMPLATES: {
+               xsltStyleItemApplyTemplatesPtr item =
+                   (xsltStyleItemApplyTemplatesPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_CHOOSE:
+            break;
+        case XSLT_FUNC_IF: {
+               xsltStyleItemIfPtr item = (xsltStyleItemIfPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_FOREACH: {
+               xsltStyleItemForEachPtr item =
+                   (xsltStyleItemForEachPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+            break;
+        case XSLT_FUNC_DOCUMENT:
+            break;
+       case XSLT_FUNC_WITHPARAM: {
+               xsltStyleItemWithParamPtr item =
+                   (xsltStyleItemWithParamPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+           break;
+       case XSLT_FUNC_PARAM: {
+               xsltStyleItemParamPtr item =
+                   (xsltStyleItemParamPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+           break;
+       case XSLT_FUNC_VARIABLE: {
+               xsltStyleItemVariablePtr item =
+                   (xsltStyleItemVariablePtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+           break;
+       case XSLT_FUNC_WHEN: {
+               xsltStyleItemWhenPtr item =
+                   (xsltStyleItemWhenPtr) comp;
+               if (item->comp != NULL)
+                   xmlXPathFreeCompExpr(item->comp);
+           }
+           break;
+       case XSLT_FUNC_OTHERWISE:
+           break;
+       default:
+           /* TODO: Raise error. */
+           break;
+    }
+#else    
     if (comp->comp != NULL)
        xmlXPathFreeCompExpr(comp->comp);
     if (comp->nsList != NULL)
        xmlFree(comp->nsList);
+#endif
 
     xmlFree(comp);
 }
@@ -326,7 +504,11 @@ xsltFreeStylePreComp(xsltStylePreCompPtr comp) {
 xsltElemPreCompPtr
 xsltDocumentComp(xsltStylesheetPtr style, xmlNodePtr inst,
                 xsltTransformFunction function ATTRIBUTE_UNUSED) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemDocumentPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *filename = NULL;
 
     /*
@@ -340,7 +522,13 @@ xsltDocumentComp(xsltStylesheetPtr style, xmlNodePtr inst,
     * (in libexslt/common.c)
     * "document" in EXSLT_COMMON_NAMESPACE
     */
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemDocumentPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_DOCUMENT);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_DOCUMENT);
+#endif
+    
     if (comp == NULL)
        return (NULL);
     comp->inst = inst;
@@ -354,7 +542,8 @@ xsltDocumentComp(xsltStylesheetPtr style, xmlNodePtr inst,
        /*
        * The element "output" is in the namespace XSLT_SAXON_NAMESPACE
        *   (http://icl.com/saxon)
-       * The @file is in no namespace.
+       * The @file is in no namespace; it is an AVT.
+       *   (http://www.computerwizards.com/saxon/doc/extensions.html#saxon:output)
        */
        filename = xsltEvalStaticAttrValueTemplate(style, inst,
                         (const xmlChar *)"file",
@@ -372,7 +561,10 @@ xsltDocumentComp(xsltStylesheetPtr style, xmlNodePtr inst,
     } else if (xmlStrEqual(inst->name, (const xmlChar *) "document")) {
        if (inst->ns != NULL) {
            if (xmlStrEqual(inst->ns->href, XSLT_NAMESPACE)) {
-               /* Mark the instruction as being of XSLT version 1.1. */
+               /*
+               * Mark the instruction as being of
+               * XSLT version 1.1 (abandoned).
+               */
                comp->ver11 = 1;
 #ifdef WITH_XSLT_DEBUG_EXTRA
                xsltGenericDebug(xsltGenericDebugContext,
@@ -398,15 +590,27 @@ xsltDocumentComp(xsltStylesheetPtr style, xmlNodePtr inst,
        /*
        * The element "document" is used in conjunction with the
        * following namespaces:
+       *
        * 1) XSLT_NAMESPACE (http://www.w3.org/1999/XSL/Transform version 1.1)
        *    <!ELEMENT xsl:document %template;>
        *    <!ATTLIST xsl:document
        *       href %avt; #REQUIRED
+       *    @href is an AVT
+       *    IMPORTANT: xsl:document was in the abandoned XSLT 1.1 draft,
+       *    it was removed and isn't available in XSLT 1.1 anymore.
+       *    In XSLT 2.0 it was renamed to xsl:result-document.
+       *
+       *   All other attributes are identical to the attributes
+       *   on xsl:output
+       *
        * 2) EXSLT_COMMON_NAMESPACE (http://exslt.org/common)
        *    <exsl:document
        *       href = { uri-reference }
+       *    TODO: is @href is an AVT?
+       *
        * 3) XSLT_XT_NAMESPACE (http://www.jclark.com/xt)
        *     Example: <xt:document method="xml" href="myFile.xml">
+       *    TODO: is @href is an AVT?
        *               
        * In all cases @href is in no namespace.
        */
@@ -437,19 +641,20 @@ error:
  */
 static void
 xsltSortComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemSortPtr comp;
+#else
     xsltStylePreCompPtr comp;
-
+#endif
     if ((style == NULL) || (inst == NULL))
        return;
-    /*
-    * <xsl:sort
-    *   select = string-expression
-    *   lang = { nmtoken }
-    *   data-type = { "text" | "number" | qname-but-not-ncname }
-    *   order = { "ascending" | "descending" }
-    *   case-order = { "upper-first" | "lower-first" } />
-    */
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemSortPtr) xsltNewStylePreComp(style, XSLT_FUNC_SORT);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_SORT);
+#endif
+    
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -537,12 +742,20 @@ xsltSortComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltCopyComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCopyPtr comp;
+#else
     xsltStylePreCompPtr comp;
-
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemCopyPtr) xsltNewStylePreComp(style, XSLT_FUNC_COPY);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_COPY);
+#endif
+    
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -566,12 +779,21 @@ xsltCopyComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltTextComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemTextPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemTextPtr) xsltNewStylePreComp(style, XSLT_FUNC_TEXT);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_TEXT);
+#endif    
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -602,7 +824,11 @@ xsltTextComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltElementComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemElementPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     /*
     * <xsl:element
@@ -614,7 +840,13 @@ xsltElementComp(xsltStylesheetPtr style, xmlNodePtr inst) {
     */
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemElementPtr) xsltNewStylePreComp(style, XSLT_FUNC_ELEMENT);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_ELEMENT);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -656,7 +888,11 @@ xsltElementComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltAttributeComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemAttributePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     /*
     * <xsl:attribute
@@ -667,7 +903,13 @@ xsltAttributeComp(xsltStylesheetPtr style, xmlNodePtr inst) {
     */
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemAttributePtr) xsltNewStylePreComp(style, XSLT_FUNC_ATTRIBUTE);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_ATTRIBUTE);
+#endif
+    
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -701,11 +943,21 @@ xsltAttributeComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltCommentComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCommentPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemCommentPtr) xsltNewStylePreComp(style, XSLT_FUNC_COMMENT);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_COMMENT);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -721,11 +973,21 @@ xsltCommentComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltProcessingInstructionComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemPIPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemPIPtr) xsltNewStylePreComp(style, XSLT_FUNC_PI);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_PI);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -745,11 +1007,21 @@ xsltProcessingInstructionComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltCopyOfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCopyOfPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemCopyOfPtr) xsltNewStylePreComp(style, XSLT_FUNC_COPYOF);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_COPYOF);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -781,12 +1053,22 @@ xsltCopyOfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltValueOfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemValueOfPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemValueOfPtr) xsltNewStylePreComp(style, XSLT_FUNC_VALUEOF);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_VALUEOF);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -828,15 +1110,31 @@ xsltValueOfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  * @inst:  the xslt with-param node
  *
  * Process the xslt with-param node on the source node
+ * Allowed parents: xsl:call-template, xsl:apply-templates.
+ * <xsl:with-param
+ *  name = qname
+ *  select = expression>
+ *  <!-- Content: template -->
+ * </xsl:with-param>
  */
 static void
 xsltWithParamComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemWithParamPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemWithParamPtr) xsltNewStylePreComp(style, XSLT_FUNC_WITHPARAM);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_WITHPARAM);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -895,12 +1193,22 @@ xsltWithParamComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltNumberComp(xsltStylesheetPtr style, xmlNodePtr cur) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemNumberPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (cur == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemNumberPtr) xsltNewStylePreComp(style, XSLT_FUNC_NUMBER);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_NUMBER);
+#endif
+
     if (comp == NULL)
        return;
     cur->psvi = comp;
@@ -1000,11 +1308,21 @@ xsltNumberComp(xsltStylesheetPtr style, xmlNodePtr cur) {
  */
 static void
 xsltApplyImportsComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemApplyImportsPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemApplyImportsPtr) xsltNewStylePreComp(style, XSLT_FUNC_APPLYIMPORTS);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_APPLYIMPORTS);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1020,12 +1338,23 @@ xsltApplyImportsComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltCallTemplateComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCallTemplatePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemCallTemplatePtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_CALLTEMPLATE);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_CALLTEMPLATE);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1068,12 +1397,23 @@ xsltCallTemplateComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltApplyTemplatesComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemApplyTemplatesPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemApplyTemplatesPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_APPLYTEMPLATES);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_APPLYTEMPLATES);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1122,11 +1462,22 @@ xsltApplyTemplatesComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltChooseComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemChoosePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemChoosePtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_CHOOSE);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_CHOOSE);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1142,11 +1493,22 @@ xsltChooseComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltIfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemIfPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemIfPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_IF);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_IF);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1177,11 +1539,22 @@ xsltIfComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltWhenComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemWhenPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemWhenPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_WHEN);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_WHEN);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1212,11 +1585,22 @@ xsltWhenComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltForEachComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemForEachPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemForEachPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_FOREACH);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_FOREACH);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1249,12 +1633,23 @@ xsltForEachComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltVariableComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemVariablePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemVariablePtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_VARIABLE);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_VARIABLE);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1313,12 +1708,23 @@ xsltVariableComp(xsltStylesheetPtr style, xmlNodePtr inst) {
  */
 static void
 xsltParamComp(xsltStylesheetPtr style, xmlNodePtr inst) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemParamPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
     const xmlChar *prop;
 
     if ((style == NULL) || (inst == NULL))
        return;
+
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemParamPtr)
+       xsltNewStylePreComp(style, XSLT_FUNC_PARAM);
+#else
     comp = xsltNewStylePreComp(style, XSLT_FUNC_PARAM);
+#endif
+
     if (comp == NULL)
        return;
     inst->psvi = comp;
@@ -1368,6 +1774,84 @@ xsltParamComp(xsltStylesheetPtr style, xmlNodePtr inst) {
     }
 }
 
+#ifdef XSLT_REFACTORED
+
+/*
+* xsltCompilerGetInScopeNSInfo:
+*
+* Create and store the list of in-scope namespaces for the given
+* node in the stylesheet. If there are no changes in the in-scope
+* namespaces then the last ns-info of the ancestor axis will be returned.
+* Compilation-time only.
+*
+* Returns the ns-info or NULL if there are no namespaces in scope.
+*/
+xsltNsListPtr
+xsltCompilerGetInScopeNSInfo(xsltCompilerCtxtPtr cctxt, xmlNodePtr node)
+{
+    xsltNsListPtr nsi = NULL;
+    xmlNsPtr *list = NULL;
+    /*
+    * Create a new ns-list for this position in the node-tree.
+    * xmlGetNsList() will return NULL, if there are no ns-decls in the
+    * tree. Note that the ns-decl for the XML namespace is not added
+    * to the resulting list; the XPath module handles the XML namespace
+    * internally.
+    */
+    list = xmlGetNsList(node->doc, node);
+    if (list == NULL)
+       return(NULL);
+    /*
+    * Initialize the list hold by the stylesheet.
+    */
+    if (cctxt->sheet->inScopeNamespaces == NULL) {
+       cctxt->sheet->inScopeNamespaces = xsltPointerListCreate();
+       if (cctxt->sheet->inScopeNamespaces == NULL) {      
+           xsltTransformError(NULL, cctxt->sheet, NULL,
+               "xsltCompilerGetInScopeNSInfo: malloc failed.\n");          
+           goto internal_err;      
+       }
+    }
+    /*
+    * Create the info-structure.
+    */
+    nsi = (xsltNsListPtr) xmlMalloc(sizeof(xsltNsList));
+    if (nsi == NULL) { 
+       xsltTransformError(NULL, cctxt->sheet, NULL,
+           "xsltCompilerGetInScopeNSInfo: malloc failed.\n");
+       goto internal_err;
+    }
+    memset(nsi, 0, sizeof(xsltNsList));
+    nsi->list = list;
+    /*
+    * Eval the number of ns-decls; this is used to speed up
+    * XPath-context initialization.
+    */
+    while (list[nsi->number] != NULL)
+       nsi->number++;
+    /*
+    * Store the ns-list in the stylesheet.
+    */
+    if (xsltPointerListAdd(
+       (xsltPointerListPtr)cctxt->sheet->inScopeNamespaces,
+       (void *) nsi) == -1)
+    {  
+       xmlFree(nsi);
+       nsi = NULL;
+       xsltTransformError(NULL, cctxt->sheet, NULL,
+           "xsltCompilerGetInScopeNSInfo: failed to add ns-info.\n");
+       goto internal_err;
+    }     
+
+    return(nsi);
+
+internal_err:
+    if (list != NULL)
+       xmlFree(list);    
+    cctxt->sheet->errors++;
+    return(NULL);
+}
+#endif /* XSLT_REFACTORED */
 
 /************************************************************************
  *                                                                     *
@@ -1407,6 +1891,12 @@ xsltFreeStylePreComps(xsltStylesheetPtr style) {
  */
 void
 xsltStylePreCompute(xsltStylesheetPtr style, xmlNodePtr inst) {
+    /*
+    * URGENT TODO: Normally inst->psvi Should never be reserved here,
+    *   BUT: since if we include the same stylesheet from
+    *   multiple imports, then the stylesheet will be parsed
+    *   again. We simply must not try to compute the stylesheet again.    
+    */
     if (inst->psvi != NULL) 
         return;
     if (IS_XSLT_ELEM(inst)) {
@@ -1543,11 +2033,23 @@ xsltStylePreCompute(xsltStylesheetPtr style, xmlNodePtr inst) {
                 "xsltStylePreCompute: unknown xsl:%s\n", inst->name);
            if (style != NULL) style->warnings++;
        }
-       /*
-        * Add the namespace lookup here, this code can be shared by
-        * all precomputations.
-        */
+       
+       
        cur = (xsltStylePreCompPtr) inst->psvi;
+
+#ifdef XSLT_REFACTORED
+       /*
+       * Assign the current list of in-scope namespaces to the
+       * item. This is needed for XPath expressions.
+       */
+       if (cur != NULL) {
+           cur->inScopeNS = XSLT_CCTXT(style)->inode->inScopeNS;                   
+       }
+#else
+       /*
+       * A ns-list is build for every XSLT item in the
+       * node-tree. This is needed for XPath expressions.
+       */
        if (cur != NULL) {
            int i = 0;
 
@@ -1558,6 +2060,7 @@ xsltStylePreCompute(xsltStylesheetPtr style, xmlNodePtr inst) {
            }
            cur->nsNr = i;
        }
+#endif
     } else {
        inst->psvi =
            (void *) xsltPreComputeExtModuleElement(style, inst);
index 423e2a7..f3b392f 100644 (file)
@@ -1960,8 +1960,13 @@ xsltApplyOneTemplateInt(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                 xmlNodePtr inst, xsltStylePreCompPtr comp)
+                 xmlNodePtr inst, xsltStylePreCompPtr castedComp)
 {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemDocumentPtr comp = (xsltStyleItemDocumentPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xsltStylesheetPtr style = NULL;
     int ret;
     xmlChar *filename = NULL, *prop, *elements;
@@ -1983,6 +1988,11 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
     if (comp->filename == NULL) {
 
         if (xmlStrEqual(inst->name, (const xmlChar *) "output")) {
+           /*
+           * The element "output" is in the namespace XSLT_SAXON_NAMESPACE
+           *   (http://icl.com/saxon)
+           * The @file is in no namespace.
+           */
 #ifdef WITH_XSLT_DEBUG_EXTRA
             xsltGenericDebug(xsltGenericDebugContext,
                              "Found saxon:output extension\n");
@@ -1990,6 +2000,7 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
             URL = xsltEvalAttrValueTemplate(ctxt, inst,
                                                  (const xmlChar *) "file",
                                                  XSLT_SAXON_NAMESPACE);
+            
            if (URL == NULL)
                URL = xsltEvalAttrValueTemplate(ctxt, inst,
                                                  (const xmlChar *) "href",
@@ -2009,6 +2020,9 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
 
                /*
                 * Trying to handle bug #59212
+                * The value of the "select" attribute is an
+                * XPath expression.
+                * (see http://xml.apache.org/xalan-j/extensionslib.html#redirect) 
                 */
                cmp = xmlXPathCompile(URL);
                 val = xsltEvalXPathString(ctxt, cmp);
@@ -2452,7 +2466,12 @@ xsltSort(xsltTransformContextPtr ctxt,
  */
 void
 xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCopyPtr comp = (xsltStyleItemCopyPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlNodePtr copy, oldInsert;
 
     oldInsert = ctxt->insert;
@@ -2647,7 +2666,12 @@ xsltText(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED,
  */
 void
 xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node,
-           xmlNodePtr inst, xsltStylePreCompPtr comp) {
+           xmlNodePtr inst, xsltStylePreCompPtr castedComp) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemElementPtr comp = (xsltStyleItemElementPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlChar *prop = NULL, *attributes = NULL, *namespace;
     const xmlChar *name;
     const xmlChar *prefix;
@@ -2670,7 +2694,7 @@ xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node,
 
     if (comp->name == NULL) {
        prop = xsltEvalAttrValueTemplate(ctxt, inst,
-                     (const xmlChar *)"name", XSLT_NAMESPACE);
+                     (const xmlChar *)"name", NULL);
        if (prop == NULL) {
            xsltTransformError(ctxt, NULL, inst,
                 "xsl:element : name is missing\n");
@@ -2705,7 +2729,7 @@ xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node,
 
     if ((comp->ns == NULL) && (comp->has_ns)) {
        namespace = xsltEvalAttrValueTemplate(ctxt, inst,
-               (const xmlChar *)"namespace", XSLT_NAMESPACE);
+               (const xmlChar *)"namespace", NULL);
        if (namespace != NULL) {
            ns = xsltGetSpecialNamespace(ctxt, inst, namespace, prefix,
                                         ctxt->insert);
@@ -2758,7 +2782,7 @@ xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node,
            xsltApplyAttributeSet(ctxt, node, inst, comp->use);
        } else {
            attributes = xsltEvalAttrValueTemplate(ctxt, inst,
-                      (const xmlChar *)"use-attribute-sets", XSLT_NAMESPACE);
+                      (const xmlChar *)"use-attribute-sets", NULL);
            if (attributes != NULL) {
                xsltApplyAttributeSet(ctxt, node, inst, attributes);
                xmlFree(attributes);
@@ -2827,7 +2851,12 @@ xsltComment(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltProcessingInstruction(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemPIPtr comp = (xsltStyleItemPIPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     const xmlChar *name;
     xmlChar *value = NULL;
     xmlNodePtr pi;
@@ -2839,7 +2868,7 @@ xsltProcessingInstruction(xsltTransformContextPtr ctxt, xmlNodePtr node,
        return;
     if (comp->name == NULL) {
        name = xsltEvalAttrValueTemplate(ctxt, inst,
-                           (const xmlChar *)"name", XSLT_NAMESPACE);
+                           (const xmlChar *)"name", NULL);
        if (name == NULL) {
            xsltTransformError(ctxt, NULL, inst,
                 "xsl:processing-instruction : name is missing\n");
@@ -2888,7 +2917,12 @@ error:
  */
 void
 xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCopyOfPtr comp = (xsltStyleItemCopyOfPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlXPathObjectPtr res = NULL;
     xmlNodeSetPtr list = NULL;
     int i;
@@ -2914,8 +2948,18 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldNsNr = ctxt->xpathCtxt->nsNr;
     oldNamespaces = ctxt->xpathCtxt->namespaces;
     ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+    if (comp->inScopeNS != NULL) {
+       ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+       ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+    } else {
+       ctxt->xpathCtxt->namespaces = NULL;
+       ctxt->xpathCtxt->nsNr = 0;
+    }
+#else
     ctxt->xpathCtxt->namespaces = comp->nsList;
     ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif
     res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
     ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
     ctxt->xpathCtxt->contextSize = oldContextSize;
@@ -2989,7 +3033,13 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemValueOfPtr comp = (xsltStyleItemValueOfPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlXPathObjectPtr res = NULL;
     xmlNodePtr copy = NULL;
     int oldProximityPosition, oldContextSize;
@@ -3014,8 +3064,18 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldNsNr = ctxt->xpathCtxt->nsNr;
     oldNamespaces = ctxt->xpathCtxt->namespaces;
     ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+    if (comp->inScopeNS != NULL) {
+       ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+       ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+    } else {
+       ctxt->xpathCtxt->namespaces = NULL;
+       ctxt->xpathCtxt->nsNr = 0;
+    }
+#else
     ctxt->xpathCtxt->namespaces = comp->nsList;
     ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif
     res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
     ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
     ctxt->xpathCtxt->contextSize = oldContextSize;
@@ -3057,8 +3117,13 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltNumber(xsltTransformContextPtr ctxt, xmlNodePtr node,
-          xmlNodePtr inst, xsltStylePreCompPtr comp)
+          xmlNodePtr inst, xsltStylePreCompPtr castedComp)
 {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemNumberPtr comp = (xsltStyleItemNumberPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     if (comp == NULL) {
        xsltTransformError(ctxt, NULL, inst,
             "xsl:number : compilation failed\n");
@@ -3111,7 +3176,14 @@ xsltApplyImports(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltCallTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemCallTemplatePtr comp =
+       (xsltStyleItemCallTemplatePtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlNodePtr cur = NULL;
     xsltStackElemPtr params = NULL, param;
 
@@ -3155,6 +3227,11 @@ xsltCallTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
             xslHandleDebugger(cur, node, comp->templ, ctxt);
 #endif
        if (ctxt->state == XSLT_STATE_STOPPED) break;
+       /*
+       * TODO: The "with-param"s could be part of the "call-template"
+       *   structure. Avoid to "search" for params dynamically
+       *   in the XML tree every time.
+       */
        if (IS_XSLT_ELEM(cur)) {
            if (IS_XSLT_NAME(cur, "with-param")) {
                param = xsltParseStylesheetCallerParam(ctxt, cur);
@@ -3198,7 +3275,14 @@ xsltCallTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
  */
 void
 xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemApplyTemplatesPtr comp =
+       (xsltStyleItemApplyTemplatesPtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlNodePtr cur, delete = NULL, oldNode;
     xmlXPathObjectPtr res = NULL;
     xmlNodeSetPtr list = NULL, oldList;
@@ -3260,8 +3344,18 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
 #endif
 
        ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+       if (comp->inScopeNS != NULL) {
+           ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+           ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+       } else {
+           ctxt->xpathCtxt->namespaces = NULL;
+           ctxt->xpathCtxt->nsNr = 0;
+       }
+#else
        ctxt->xpathCtxt->namespaces = comp->nsList;
        ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif
        res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
        ctxt->xpathCtxt->contextSize = oldContextSize;
        ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
@@ -3398,8 +3492,13 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
     while (cur!=NULL) {
 #ifdef WITH_DEBUGGER
         if (ctxt->debugStatus != XSLT_DEBUG_NONE)
+#ifdef XSLT_REFACTORED
+            xslHandleDebugger(cur, node, NULL, ctxt);
+#else
+           /* TODO: Isn't comp->templ always NULL for apply-template? */
             xslHandleDebugger(cur, node, comp->templ, ctxt);
 #endif
+#endif
         if (ctxt->state == XSLT_STATE_STOPPED) break;
         if (IS_XSLT_ELEM(cur)) {
             if (IS_XSLT_NAME(cur, "with-param")) {
@@ -3500,7 +3599,8 @@ error:
  */
 void
 xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
-          xmlNodePtr inst, xsltStylePreCompPtr comp ATTRIBUTE_UNUSED) {
+          xmlNodePtr inst, xsltStylePreCompPtr comp ATTRIBUTE_UNUSED)
+{
     xmlXPathObjectPtr res = NULL;
     xmlNodePtr replacement, when;
     int doit = 1;
@@ -3528,7 +3628,12 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
     while ((IS_XSLT_ELEM(replacement) && (IS_XSLT_NAME(replacement, "when")))
            || xmlIsBlankNode(replacement)) {
+#ifdef XSLT_REFACTORED
+       xsltStyleItemWhenPtr wcomp =
+           (xsltStyleItemWhenPtr) replacement->psvi;
+#else
        xsltStylePreCompPtr wcomp = replacement->psvi;
+#endif
 
        if (xmlIsBlankNode(replacement)) {
            replacement = replacement->next;
@@ -3545,8 +3650,13 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
 
 #ifdef WITH_DEBUGGER
         if (xslDebugStatus != XSLT_DEBUG_NONE)
+#ifdef XSLT_REFACTORED
+            xslHandleDebugger(when, node, NULL, ctxt);
+#else
+           /* TODO: Isn't comp->templ always NULL for xsl:choose? */
             xslHandleDebugger(when, node, comp->templ, ctxt);
 #endif
+#endif
 
 #ifdef WITH_XSLT_DEBUG_PROCESS
        XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugContext,
@@ -3558,8 +3668,18 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
        oldNsNr = ctxt->xpathCtxt->nsNr;
        oldNamespaces = ctxt->xpathCtxt->namespaces;
        ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+       if (wcomp->inScopeNS != NULL) {
+           ctxt->xpathCtxt->namespaces = wcomp->inScopeNS->list;
+           ctxt->xpathCtxt->nsNr = wcomp->inScopeNS->number;
+       } else {
+           ctxt->xpathCtxt->namespaces = NULL;
+           ctxt->xpathCtxt->nsNr = 0;
+       }
+#else
        ctxt->xpathCtxt->namespaces = wcomp->nsList;
        ctxt->xpathCtxt->nsNr = wcomp->nsNr;
+#endif
        res = xmlXPathCompiledEval(wcomp->comp, ctxt->xpathCtxt);
        ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
        ctxt->xpathCtxt->contextSize = oldContextSize;
@@ -3598,8 +3718,13 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
     if (IS_XSLT_ELEM(replacement) && (IS_XSLT_NAME(replacement, "otherwise"))) {
 #ifdef WITH_DEBUGGER
         if (xslDebugStatus != XSLT_DEBUG_NONE)
+#ifdef XSLT_REFACTORED
+            xslHandleDebugger(replacement, node, NULL, ctxt);
+#else
+           /* TODO: Isn't comp->templ always NULL for xsl:otherwise? */
             xslHandleDebugger(replacement, node, comp->templ, ctxt);
 #endif
+#endif
 
 #ifdef WITH_XSLT_DEBUG_PROCESS
        XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugContext,
@@ -3635,7 +3760,12 @@ error:
  */
 void
 xsltIf(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp){
+#ifdef XSLT_REFACTORED
+       xsltStyleItemIfPtr comp = (xsltStyleItemIfPtr) castedComp;
+#else
+       xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlXPathObjectPtr res = NULL;
     int doit = 1;
     int oldContextSize, oldProximityPosition;
@@ -3660,8 +3790,18 @@ xsltIf(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldNsNr = ctxt->xpathCtxt->nsNr;
     oldNamespaces = ctxt->xpathCtxt->namespaces;
     ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+    if (comp->inScopeNS != NULL) {
+       ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+       ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+    } else {
+       ctxt->xpathCtxt->namespaces = NULL;
+       ctxt->xpathCtxt->nsNr = 0;
+    }
+#else
     ctxt->xpathCtxt->namespaces = comp->nsList;
     ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif
     res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
     ctxt->xpathCtxt->contextSize = oldContextSize;
     ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
@@ -3707,7 +3847,13 @@ error:
  */
 void
 xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                  xmlNodePtr inst, xsltStylePreCompPtr comp) {
+                  xmlNodePtr inst, xsltStylePreCompPtr castedComp)
+{
+#ifdef XSLT_REFACTORED
+       xsltStyleItemForEachPtr comp = (xsltStyleItemForEachPtr) castedComp;
+#else
+       xsltStylePreCompPtr comp = castedComp;
+#endif
     xmlXPathObjectPtr res = NULL;
     xmlNodePtr replacement;
     xmlNodeSetPtr list = NULL, oldList;
@@ -3739,8 +3885,18 @@ xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldNsNr = ctxt->xpathCtxt->nsNr;
     oldNamespaces = ctxt->xpathCtxt->namespaces;
     ctxt->xpathCtxt->node = node;
+#ifdef XSLT_REFACTORED
+    if (comp->inScopeNS != NULL) {
+       ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+       ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+    } else {
+       ctxt->xpathCtxt->namespaces = NULL;
+       ctxt->xpathCtxt->nsNr = 0;
+    }
+#else
     ctxt->xpathCtxt->namespaces = comp->nsList;
     ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif   
     oldCDocPtr = ctxt->document;
     oldXDocPtr = ctxt->xpathCtxt->doc;
     res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
index 48e6292..88caf17 100644 (file)
@@ -424,7 +424,14 @@ xsltAddStackElemList(xsltTransformContextPtr ctxt, xsltStackElemPtr elems) {
  */
 static xmlXPathObjectPtr
 xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr elem,
-                xsltStylePreCompPtr precomp) {
+                xsltStylePreCompPtr castedComp)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemVariablePtr precomp =
+       (xsltStyleItemVariablePtr) castedComp;
+#else
+    xsltStylePreCompPtr precomp = castedComp;
+#endif   
     xmlXPathObjectPtr result = NULL;
     int oldProximityPosition, oldContextSize;
     xmlNodePtr oldInst, oldNode;
@@ -459,8 +466,18 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr elem,
        oldNamespaces = ctxt->xpathCtxt->namespaces;
        if (precomp != NULL) {
            ctxt->inst = precomp->inst;
+#ifdef XSLT_REFACTORED
+           if (precomp->inScopeNS != NULL) {
+               ctxt->xpathCtxt->namespaces = precomp->inScopeNS->list;
+               ctxt->xpathCtxt->nsNr = precomp->inScopeNS->number;
+           } else {
+               ctxt->xpathCtxt->namespaces = NULL;
+               ctxt->xpathCtxt->nsNr = 0;
+           }
+#else
            ctxt->xpathCtxt->namespaces = precomp->nsList;
            ctxt->xpathCtxt->nsNr = precomp->nsNr;
+#endif
        } else {
            ctxt->inst = NULL;
            ctxt->xpathCtxt->namespaces = NULL;
@@ -549,9 +566,14 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr elem,
  * Returns the XPath Object value or NULL in case of error
  */
 static xmlXPathObjectPtr
-xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) {
+xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt)
+{
     xmlXPathObjectPtr result = NULL;
+#ifdef XSLT_REFACTORED
+    xsltStyleBasicItemVariablePtr precomp;
+#else
     xsltStylePreCompPtr precomp;
+#endif    
     int oldProximityPosition, oldContextSize;
     xmlDocPtr oldDoc;
     xmlNodePtr oldInst;
@@ -579,7 +601,11 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) {
     name = elem->name;
     elem->name = BAD_CAST "  being computed ... ";
 
+#ifdef XSLT_REFACTORED
+    precomp = (xsltStyleBasicItemVariablePtr) elem->comp;
+#else
     precomp = elem->comp;
+#endif
     if (elem->select != NULL) {
        xmlXPathCompExprPtr comp = NULL;
 
@@ -601,8 +627,18 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) {
        
        if (precomp != NULL) {
            ctxt->inst = precomp->inst;
+#ifdef XSLT_REFACTORED
+           if (precomp->inScopeNS != NULL) {
+               ctxt->xpathCtxt->namespaces = precomp->inScopeNS->list;
+               ctxt->xpathCtxt->nsNr = precomp->inScopeNS->number;
+           } else {
+               ctxt->xpathCtxt->namespaces = NULL;
+               ctxt->xpathCtxt->nsNr = 0;
+           }
+#else
            ctxt->xpathCtxt->namespaces = precomp->nsList;
            ctxt->xpathCtxt->nsNr = precomp->nsNr;
+#endif
        } else {
            ctxt->inst = NULL;
            ctxt->xpathCtxt->namespaces = NULL;
@@ -1175,8 +1211,16 @@ xsltQuoteOneUserParam(xsltTransformContextPtr ctxt,
  * Returns the xsltStackElemPtr or NULL in case of error
  */
 static xsltStackElemPtr
-xsltBuildVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
-                 xmlNodePtr tree) {
+xsltBuildVariable(xsltTransformContextPtr ctxt,
+                 xsltStylePreCompPtr castedComp,
+                 xmlNodePtr tree)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleBasicItemVariablePtr comp =
+       (xsltStyleBasicItemVariablePtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif 
     xsltStackElemPtr elem;
 
 #ifdef WITH_XSLT_DEBUG_VARIABLE
@@ -1191,7 +1235,7 @@ xsltBuildVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
     elem = xsltNewStackElem();
     if (elem == NULL)
        return(NULL);
-    elem->comp = comp;
+    elem->comp = (xsltStylePreCompPtr) comp;
     elem->name = comp->name;
     if (comp->select != NULL)
        elem->select = comp->select;
@@ -1201,7 +1245,8 @@ xsltBuildVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
        elem->nameURI = comp->ns;
     elem->tree = tree;
     if (elem->computed == 0) {
-       elem->value = xsltEvalVariable(ctxt, elem, comp);
+       elem->value = xsltEvalVariable(ctxt, elem,
+           (xsltStylePreCompPtr) comp);
        if (elem->value != NULL)
            elem->computed = 1;
     }
@@ -1215,13 +1260,22 @@ xsltBuildVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
  * @tree:  the tree if select is NULL
  * @param:  this is a parameter actually
  *
- * Computes and register a new variable value. 
+ * Computes and register a new variable value.
+ * TODO: Is this intended for xsl:param as well?
  *
  * Returns 0 in case of success, -1 in case of error
  */
 static int
-xsltRegisterVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
-                    xmlNodePtr tree, int param) {
+xsltRegisterVariable(xsltTransformContextPtr ctxt,
+                    xsltStylePreCompPtr castedComp,
+                    xmlNodePtr tree, int param)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleBasicItemVariablePtr comp =
+       (xsltStyleBasicItemVariablePtr) castedComp;
+#else
+    xsltStylePreCompPtr comp = castedComp;
+#endif
     xsltStackElemPtr elem;
     int present;
 
@@ -1244,7 +1298,7 @@ xsltRegisterVariable(xsltTransformContextPtr ctxt, xsltStylePreCompPtr comp,
 #endif
        return(0);
     }
-    elem = xsltBuildVariable(ctxt, comp, tree);
+    elem = xsltBuildVariable(ctxt, (xsltStylePreCompPtr) comp, tree);
     xsltAddStackElem(ctxt, elem);
     return(0);
 }
@@ -1344,14 +1398,23 @@ xsltVariableLookup(xsltTransformContextPtr ctxt, const xmlChar *name,
  */
 
 xsltStackElemPtr
-xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
+xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr cur)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleBasicItemVariablePtr comp;
+#else
+    xsltStylePreCompPtr comp;
+#endif
     xmlNodePtr tree = NULL;
     xsltStackElemPtr elem = NULL;
-    xsltStylePreCompPtr comp;
-
+    
     if ((cur == NULL) || (ctxt == NULL))
        return(NULL);
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleBasicItemVariablePtr) cur->psvi;
+#else
     comp = (xsltStylePreCompPtr) cur->psvi;
+#endif     
     if (comp == NULL) {
        xsltTransformError(ctxt, NULL, cur,
            "xsl:param : compilation error\n");
@@ -1379,7 +1442,7 @@ xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
        tree = cur;
     }
 
-    elem = xsltBuildVariable(ctxt, comp, tree);
+    elem = xsltBuildVariable(ctxt, (xsltStylePreCompPtr) comp, tree);
 
     return(elem);
 }
@@ -1394,14 +1457,23 @@ xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
  */
 
 void
-xsltParseGlobalVariable(xsltStylesheetPtr style, xmlNodePtr cur) {
+xsltParseGlobalVariable(xsltStylesheetPtr style, xmlNodePtr cur)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemVariablePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((cur == NULL) || (style == NULL))
        return;
 
     xsltStylePreCompute(style, cur);
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemVariablePtr) cur->psvi;
+#else
     comp = (xsltStylePreCompPtr) cur->psvi;
+#endif
     if (comp == NULL) {
        xsltTransformError(NULL, style, cur,
             "xsl:variable : compilation failed\n");
@@ -1422,8 +1494,9 @@ xsltParseGlobalVariable(xsltStylesheetPtr style, xmlNodePtr cur) {
        "Registering global variable %s\n", comp->name);
 #endif
 
-    xsltRegisterGlobalVariable(style, comp->name, comp->ns, comp->select,
-                              cur->children, comp, NULL);
+    xsltRegisterGlobalVariable(style, comp->name, comp->ns,
+       comp->select, cur->children, (xsltStylePreCompPtr) comp,
+       NULL);
 }
 
 /**
@@ -1437,13 +1510,21 @@ xsltParseGlobalVariable(xsltStylesheetPtr style, xmlNodePtr cur) {
 
 void
 xsltParseGlobalParam(xsltStylesheetPtr style, xmlNodePtr cur) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemParamPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((cur == NULL) || (style == NULL))
        return;
 
     xsltStylePreCompute(style, cur);
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemParamPtr) cur->psvi;
+#else
     comp = (xsltStylePreCompPtr) cur->psvi;
+#endif    
     if (comp == NULL) {
        xsltTransformError(NULL, style, cur,
             "xsl:param : compilation failed\n");
@@ -1465,8 +1546,9 @@ xsltParseGlobalParam(xsltStylesheetPtr style, xmlNodePtr cur) {
        "Registering global param %s\n", comp->name);
 #endif
 
-    xsltRegisterGlobalVariable(style, comp->name, comp->ns, comp->select,
-                              cur->children, comp, NULL);
+    xsltRegisterGlobalVariable(style, comp->name, comp->ns,
+       comp->select, cur->children, (xsltStylePreCompPtr) comp,
+       NULL);
 }
 
 /**
@@ -1479,13 +1561,22 @@ xsltParseGlobalParam(xsltStylesheetPtr style, xmlNodePtr cur) {
  */
 
 void
-xsltParseStylesheetVariable(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
+xsltParseStylesheetVariable(xsltTransformContextPtr ctxt, xmlNodePtr cur)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemVariablePtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((cur == NULL) || (ctxt == NULL))
        return;
 
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemVariablePtr) cur->psvi;
+#else
     comp = (xsltStylePreCompPtr) cur->psvi;
+#endif   
     if (comp == NULL) {
        xsltTransformError(ctxt, NULL, cur,
             "xsl:variable : compilation failed\n");
@@ -1503,7 +1594,7 @@ xsltParseStylesheetVariable(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
        "Registering variable %s\n", comp->name));
 #endif
 
-    xsltRegisterVariable(ctxt, comp, cur->children, 0);
+    xsltRegisterVariable(ctxt, (xsltStylePreCompPtr) comp, cur->children, 0);
 }
 
 /**
@@ -1516,13 +1607,21 @@ xsltParseStylesheetVariable(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
  */
 
 void
-xsltParseStylesheetParam(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
+xsltParseStylesheetParam(xsltTransformContextPtr ctxt, xmlNodePtr cur)
+{
+#ifdef XSLT_REFACTORED
+    xsltStyleItemParamPtr comp;
+#else
     xsltStylePreCompPtr comp;
+#endif
 
     if ((cur == NULL) || (ctxt == NULL))
        return;
-
+#ifdef XSLT_REFACTORED
+    comp = (xsltStyleItemParamPtr) cur->psvi;
+#else
     comp = (xsltStylePreCompPtr) cur->psvi;
+#endif 
     if (comp == NULL) {
        xsltTransformError(ctxt, NULL, cur,
             "xsl:param : compilation failed\n");
@@ -1540,7 +1639,7 @@ xsltParseStylesheetParam(xsltTransformContextPtr ctxt, xmlNodePtr cur) {
        "Registering param %s\n", comp->name));
 #endif
 
-    xsltRegisterVariable(ctxt, comp, cur->children, 1);
+    xsltRegisterVariable(ctxt, (xsltStylePreCompPtr) comp, cur->children, 1);
 }
 
 /**
index dab816b..63a7ed8 100644 (file)
@@ -369,6 +369,9 @@ xsltFreeTemplateList(xsltTemplatePtr template) {
 xsltStylesheetPtr
 xsltNewStylesheet(void) {
     xsltStylesheetPtr cur;
+#ifdef XSLT_REFACTORED
+    xsltCompilerCtxtPtr cctxt;
+#endif
 
     cur = (xsltStylesheetPtr) xmlMalloc(sizeof(xsltStylesheet));
     if (cur == NULL) {
@@ -377,6 +380,26 @@ xsltNewStylesheet(void) {
        return(NULL);
     }
     memset(cur, 0, sizeof(xsltStylesheet));
+#ifdef XSLT_REFACTORED
+    /*
+    * Create the compiler context.
+    */
+    cctxt = (xsltCompilerCtxtPtr) xmlMalloc(sizeof(xsltCompilerCtxt));
+    if (cctxt == NULL) {
+       xmlFree(cur);
+       xsltTransformError(NULL, NULL, NULL,
+               "xsltNewStylesheet : malloc of compilation context failed\n");
+       return(NULL);
+    }
+    memset(cctxt, 0, sizeof(xsltCompilerCtxt));
+    cur->compCtxt = (void *) cctxt;
+    cctxt->sheet = cur;
+#endif
+    /*
+    * TODO: This here seems to be the best place where to create
+    *   the compilation context, right?
+    */
+           
     cur->omitXmlDeclaration = -1;
     cur->standalone = -1;
     cur->decimalFormat = xsltNewDecimalFormat(NULL);
@@ -487,6 +510,58 @@ xsltFreeStylesheetList(xsltStylesheetPtr sheet) {
     }
 }
 
+#ifdef XSLT_REFACTORED
+/**
+ * xsltFreeInScopeNamespaces:
+ * @sheet:  an XSLT stylesheet
+ *
+ * Frees the list of in-scope namespace lists.
+ */
+static void
+xsltFreeInScopeNamespaces(xsltStylesheetPtr sheet)
+{
+    if (sheet->inScopeNamespaces == NULL)
+       return;
+    else {
+       int i;
+       xsltNsListPtr nsi;
+       xsltPointerListPtr list = sheet->inScopeNamespaces;
+
+       for (i = 0; i < list->number; i++) {
+           /*
+           * REVISIT TODO: Free info of in-scope namespaces.
+           */
+           nsi = (xsltNsListPtr) list->items[i];
+           if (nsi->list != NULL)
+               xmlFree(nsi->list);
+           xmlFree(nsi);
+       }
+       xsltPointerListFree(list);
+       sheet->inScopeNamespaces = NULL;
+    }
+    return;
+}
+
+static void
+xsltCompilerCtxtFree(xsltCompilerCtxtPtr cctxt)
+{    
+    if (cctxt == NULL)
+       return;
+    /*
+    * Free node-infos.
+    */
+    if (cctxt->inodeList != NULL) {
+       xsltCompilerNodeInfoPtr tmp, cur = cctxt->inodeList;
+       while (cur != NULL) {
+           tmp = cur;
+           cur = cur->next;
+           xmlFree(tmp);
+       }
+    }
+    xmlFree(cctxt);
+}
+#endif
+
 /**
  * xsltFreeStylesheet:
  * @sheet:  an XSLT stylesheet
@@ -506,6 +581,10 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet)
     xsltFreeTemplateList(sheet->templates);
     xsltFreeAttributeSetsHashes(sheet);
     xsltFreeNamespaceAliasHashes(sheet);
+#ifdef XSLT_REFACTORED
+    if (sheet->inScopeNamespaces != NULL)
+       xsltFreeInScopeNamespaces(sheet);
+#endif
     xsltFreeStyleDocuments(sheet);
     xsltFreeStylePreComps(sheet);
     xsltShutdownExts(sheet);
@@ -541,6 +620,15 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet)
 
     if (sheet->imports != NULL)
         xsltFreeStylesheetList(sheet->imports);
+#ifdef XSLT_REFACTORED
+    /*
+    * TODO: Just a paranoid cleanup, in case the compilation
+    *   context was not freed after the compilation.
+    */
+    if (sheet->compCtxt != NULL) {
+       xsltCompilerCtxtFree((xsltCompilerCtxtPtr) sheet->compCtxt);
+    }
+#endif
 
 #ifdef WITH_XSLT_DEBUG
     xsltGenericDebug(xsltGenericDebugContext,
@@ -683,7 +771,7 @@ xsltParseStylesheetOutput(xsltStylesheetPtr style, xmlNodePtr cur)
 
     if ((cur == NULL) || (style == NULL))
         return;
-    
+   
     prop = xmlGetNsProp(cur, (const xmlChar *) "version", NULL);
     if (prop != NULL) {
         if (style->version != NULL)
@@ -854,6 +942,13 @@ xsltParseStylesheetOutput(xsltStylesheetPtr style, xmlNodePtr cur)
  * @style:  the XSLT stylesheet
  * @cur:  the "decimal-format" element
  *
+ * <!-- Category: top-level-element -->
+ * <xsl:decimal-format
+ *   name = qname, decimal-separator = char, grouping-separator = char,
+ *   infinity = string, minus-sign = char, NaN = string, percent = char
+ *   per-mille = char, zero-digit = char, digit = char,
+ * pattern-separator = char />
+ *
  * parse an XSLT stylesheet decimal-format element and
  * and record the formatting characteristics
  */
@@ -1213,6 +1308,74 @@ xsltParseStylesheetExcludePrefix(xsltStylesheetPtr style, xmlNodePtr cur,
     return(nb);
 }
 
+#ifdef XSLT_REFACTORED
+
+static xsltCompilerNodeInfoPtr
+xsltCompilerNodePush(xsltCompilerCtxtPtr cctxt, xmlNodePtr node)
+{    
+    if ((cctxt->inode != NULL) && (cctxt->inode->next != NULL)) {      
+       cctxt->inode = cctxt->inode->next;
+    } else if ((cctxt->inode == NULL) && (cctxt->inodeList != NULL)) {
+       cctxt->inode = cctxt->inodeList;        
+    } else {
+       /*
+       * Create a new node-info.
+       */
+       cctxt->inode = (xsltCompilerNodeInfoPtr)
+           xmlMalloc(sizeof(xsltCompilerNodeInfo));
+       if (cctxt->inode == NULL) {
+           xsltTransformError(NULL, cctxt->sheet, NULL,
+               "xsltCompilerNodePush: malloc failed.\n");
+           return(NULL);
+       }
+       memset(cctxt->inode, 0, sizeof(xsltCompilerNodeInfo));
+       if (cctxt->inodeList == NULL)
+           cctxt->inodeList = cctxt->inode;
+       else {
+           cctxt->inodeLast->next = cctxt->inode;
+           cctxt->inode->prev = cctxt->inodeLast;
+       }
+       cctxt->inodeLast = cctxt->inode;
+    }
+    /*
+    * REVISIT TODO: Keep the reset always complete.
+    */
+    cctxt->depth++;
+    cctxt->inode->depth = cctxt->depth;
+    cctxt->inode->templ = NULL;
+    cctxt->inode->item = NULL;
+    cctxt->inode->node = node;
+    /*
+    * Inherit the list of in-scope namespaces.
+    */
+    if (cctxt->inode->prev != NULL)
+       cctxt->inode->inScopeNS = cctxt->inode->prev->inScopeNS;
+    else
+       cctxt->inode->inScopeNS = NULL;
+    
+    return(cctxt->inode);
+}
+
+static void
+xsltCompilerNodePop(xsltCompilerCtxtPtr cctxt, xmlNodePtr node)
+{    
+    if (cctxt->inode == NULL) {
+       xmlGenericError(xmlGenericErrorContext,
+           "xsltCompilerNodePop: Top-node mismatch.\n");
+       return;
+    }          
+    if (cctxt->inode->node != node)
+       xmlGenericError(xmlGenericErrorContext,
+       "xsltCompilerNodePop: Node mismatch.\n");
+    if (cctxt->inode->depth != cctxt->depth)
+       xmlGenericError(xmlGenericErrorContext,
+       "xsltCompilerNodePop: Depth mismatch.\n");
+    cctxt->depth--;
+    cctxt->inode = cctxt->inode->prev;
+}
+
+#endif
+
 /**
  * xsltPrecomputeStylesheet:
  * @style:  the XSLT stylesheet
@@ -1222,13 +1385,25 @@ xsltParseStylesheetExcludePrefix(xsltStylesheetPtr style, xmlNodePtr cur,
  * and run the preprocessing of all XSLT constructs.
  *
  * and process xslt:text
+ *
+ * URGENT TODO: In order to avoid separation of the parsing of the stylesheet's
+ *   node-tree, this should either only strip whitespace-only text-nodes,
+ *   or it should be merged completely with the stylesheet-parsing
+ *   functions (e.g. xsltParseStylesheetTop()).
  */
 static void
 xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
     xmlNodePtr delete;
     int internalize = 0;
+#ifdef XSLT_REFACTORED
+    xsltCompilerCtxtPtr cctxt;
+#endif
 
-    if ((style == NULL) || (cur == NULL))
+    if ((style == NULL) || (cur == NULL)
+#ifdef XSLT_REFACTORED
+       ||(style->compCtxt == NULL)
+#endif
+       )
         return;
 
     if ((cur->doc != NULL) && (style->dict != NULL) &&
@@ -1236,7 +1411,9 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
        internalize = 1;
     else
         style->internalized = 0;
-
+#ifdef XSLT_REFACTORED
+    cctxt = (xsltCompilerCtxtPtr) style->compCtxt;    
+#endif
     /*
      * This content comes from the stylesheet
      * For stylesheets, the set of whitespace-preserving
@@ -1254,8 +1431,11 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
            delete = NULL;
        }
        if (cur->type == XML_ELEMENT_NODE) {
-           int exclPrefixes;
+           int exclPrefixes;       
 
+#ifdef XSLT_REFACTORED
+           xsltCompilerNodePush(cctxt, cur);
+#endif
            /*
             * Internalize attributes values.
             */
@@ -1285,30 +1465,57 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
                    prop = prop->next;
                }
            }
-
-           /*     
-           * SPEC "A namespace URI is designated as an excluded namespace
-           *   by using an exclude-result-prefixes attribute on an
-           *   xsl:stylesheet element or an xsl:exclude-result-prefixes
-           *   attribute on a literal result element."
-           * TODO: The evaluation of "exclude-result-prefixes" is still not
-           *   correrct here, since we apply this to extension elements as
-           *   well. So either we need to be extension-element-aware here
-           *   or move this to an other layer.
+           /*
+           * TODO: "exclude-result-prefixes"
+           *   SPEC 1.0:
+           *   "exclude-result-prefixes" is only allowed on literal
+           *   result elements and "xsl:exclude-result-prefixes" only
+           *   on xsl:stylesheet/xsl:transform.
+           *   SPEC 2.0:
+           *   "There are a number of standard attributes
+           *   that may appear on any XSLT element: specifically version,
+           *   exclude-result-prefixes, extension-element-prefixes,
+           *   xpath-default-namespace, default-collation, and use-when."
            */
            if (IS_XSLT_ELEM(cur)) {
-               exclPrefixes = xsltParseStylesheetExcludePrefix(style, cur, 1);
+               exclPrefixes = 0;
+#ifdef XSLT_REFACTORED
+               if ((cctxt->depth == 0) && (cur->nsDef != NULL)) {
+                   /*
+                   * In every case, we need the in-scope namespaces of the
+                   * element, where the stylesheet is rooted at.
+                   * Otherwise we need to pre-compute the in-scope namespaces
+                   * only if there's a new ns-decl.
+                   */
+                   cctxt->inode->inScopeNS =
+                       xsltCompilerGetInScopeNSInfo(cctxt, cur);
+               }
+#endif         
                xsltStylePreCompute(style, cur);
                if (IS_XSLT_NAME(cur, "text")) {
                    for (;exclPrefixes > 0;exclPrefixes--)
                        exclPrefixPop(style);
                    goto skip_children;
                }
-           } else
+           } else {
+#ifdef XSLT_REFACTORED
+               if (cctxt->depth == 0)
+                   cctxt->inode->inScopeNS =
+                       xsltCompilerGetInScopeNSInfo(cctxt, cur);
+#endif
                exclPrefixes = xsltParseStylesheetExcludePrefix(style, cur, 0);
+           }
 
            /*
             * Remove excluded prefixes
+            * TODO BUG:
+            *   This will incorrectly apply excluded-result-prefixes
+            *   of the including stylesheet to the included stylesheet.
+            *   We need to localize the list of excluded-prefixes for
+            *   every processed stylesheet.
+            * SPEC 1.0: "a subtree rooted at an xsl:stylesheet element
+            *   does not include any stylesheets imported or included by
+            *   children of that xsl:stylesheet element."
             */
            if ((cur->nsDef != NULL) && (style->exclPrefixNr > 0)) {
                xmlNsPtr ns = cur->nsDef, prev = NULL, next;
@@ -1393,13 +1600,20 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
                continue;
            }
        }
+#ifdef XSLT_REFACTORED
+       if (cur->type == XML_ELEMENT_NODE) {
+           /* Leaving the scope of an element-node. */
+           xsltCompilerNodePop(cctxt, cur);
+       }
+#endif
+
 skip_children:
        if (cur->next != NULL) {
            cur = cur->next;
            continue;
-       }
-       
+       }       
        do {
+
            cur = cur->parent;
            if (cur == NULL)
                break;
@@ -1444,6 +1658,13 @@ xsltGatherNamespaces(xsltStylesheetPtr style) {
      *       patterns, well they may be in problem, hopefully they will get
      *       a warning first.
      */
+    /*
+    * TODO: Eliminate the use of the hash for XPath expressions.
+    *   An expression should be evaluated in the context of the in-scope
+    *   namespaces; eliminate the restriction of an XML document to contain
+    *   no duplicate prefixes for different namespace names.
+    * 
+    */
     cur = xmlDocGetRootElement(style->doc);
     while (cur != NULL) {
        if (cur->type == XML_ELEMENT_NODE) {
@@ -1714,6 +1935,9 @@ skip_children:
  * @style:  the XSLT stylesheet
  * @key:  the "key" element
  *
+ * <!-- Category: top-level-element -->
+ * <xsl:key name = qname, match = pattern, use = expression />
+ *
  * parse an XSLT stylesheet key definition and register it
  */
 
@@ -1820,6 +2044,10 @@ xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) {
     /*
      * Get inherited namespaces
      */
+    /*
+    * TODO: Apply the optimized in-scope-namespace mechanism
+    *   as for the other XSLT instructions.
+    */
     xsltGetInheritedNsList(style, ret, template);
 
     /*
@@ -1918,6 +2146,86 @@ error:
     return;
 }
 
+#ifdef XSLT_REFACTORED_PARSING
+/*
+* xsltParseStylesheetTreeNew:
+*
+* Parses and compiles an XSLT stylesheet's XML tree.
+*
+* TODO: Adjust error report text.
+*/
+static int
+xsltParseStylesheetTreeNew(xsltStylesheetPtr sheet, xmlNodePtr cur)
+{
+    xsltCompilerCtxtPtr cctxt;
+    xmlNodePtr top = cur;
+    int depth = 0, simpleSyntax = 0;
+
+    if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE) ||
+       (sheet == NULL) || (sheet->compCtxt == NULL))
+       return(-1);
+    cctxt = (xsltCompilerCtxtPtr) sheet->compCtxt;
+
+    /*
+    * Evalute if we have a simplified syntax.
+    */
+    if ((IS_XSLT_ELEM(cur)) && 
+       ((IS_XSLT_NAME(cur, "stylesheet")) ||
+        (IS_XSLT_NAME(cur, "transform"))))
+    {  
+#ifdef WITH_XSLT_DEBUG_PARSING
+       xsltGenericDebug(xsltGenericDebugContext,
+               "xsltParseStylesheetProcess : found stylesheet\n");
+#endif
+       /*
+       * TODO: Initialize.
+       */
+    } else {
+       simpleSyntax = 1;       
+       /*
+       * TODO: Create the initial template.
+       * TODO: Initialize.
+       */
+    }        
+    /*
+    * Reset the compiler context.
+    */
+    cctxt->depth = 0;
+    cctxt->inode = NULL;
+    /*
+    * Initialize the in-scope namespaces. We need to have
+    * the in-scope ns-decls of the first given node, regardless
+    * if it's a XSLT instruction or a literal result element.
+    */
+    xsltCompilerNodePush(cctxt, cur);
+    xsltCompilerGetInScopeNSInfo(cctxt, cur);
+    goto next_sibling;
+
+    while (cur != NULL) {
+       if (cur->type == XML_ELEMENT_NODE) {
+           
+       }
+
+next_sibling:
+       if (cur->type == XML_ELEMENT_NODE) {
+           /*
+           * Leaving an element.
+           */
+           xsltCompilerNodePop(cctxt, cur);
+       }
+       if (cur == top)
+           break;
+       if (cur->next != NULL)
+           cur = cur->next;
+       else {
+           cur = cur->parent;
+           goto next_sibling;
+       }       
+    }
+    return(0);
+}
+#endif /* XSLT_REFACTORED_PARSING */
+
 /**
  * xsltParseStylesheetTop:
  * @style:  the XSLT stylesheet
@@ -1925,7 +2233,6 @@ error:
  *
  * scan the top level elements of an XSL stylesheet
  */
-
 static void
 xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
     xmlNodePtr cur;
@@ -2112,11 +2419,24 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) {
        xsltParseStylesheetExtPrefix(ret, cur, 0);
        ret->literal_result = 1;
     }
-    if (!ret->nopreproc)
+    if (!ret->nopreproc) {
+#ifdef XSLT_REFACTORED
+       /*
+       * Reset the compiler context.
+       * TODO: This all looks ugly; but note that this will go
+       *   into an other function; it's just temporarily here.
+       */
+       XSLT_CCTXT(ret)->depth = -1;
+       XSLT_CCTXT(ret)->inode = NULL;
+#endif
        xsltPrecomputeStylesheet(ret, cur);
+#ifdef XSLT_REFACTORED
+       XSLT_CCTXT(ret)->depth = -1;
+       XSLT_CCTXT(ret)->inode = NULL;
+#endif
+    }
 
     if (ret->literal_result == 0) {
-
        xsltParseStylesheetTop(ret, cur);
     } else {
        xmlChar *prop;
@@ -2190,6 +2510,7 @@ xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr style) {
     ret = xsltNewStylesheet();
     if (ret == NULL)
        return(NULL);
+    
     if (doc->dict != NULL) {
         xmlDictFree(ret->dict);
        ret->dict = doc->dict;
@@ -2238,7 +2559,17 @@ xsltParseStylesheetDoc(xmlDocPtr doc) {
        return(NULL);
 
     xsltResolveStylesheetAttributeSet(ret);
-
+#ifdef XSLT_REFACTORED
+    /*
+    * Free the compilation context.
+    * TODO: Check if it's better to move this cleanup to
+    *   xsltParseStylesheetImportedDoc().
+    */
+    if (ret->compCtxt != NULL) {
+       xsltCompilerCtxtFree(XSLT_CCTXT(ret));
+       ret->compCtxt = NULL;
+    }
+#endif
     return(ret);
 }
 
index 2c6b54e..a79096d 100644 (file)
 extern "C" {
 #endif
 
+
+/**
+ * XSLT_REFACTORED:
+ *
+ * Internal define to enable the refactored parts of Libxslt
+ * mostly related to pre-computation.
+ */
+/* #define XSLT_REFACTORED */
+
+/**
+ * XSLT_REFACTORED_PARSING:
+ *
+ * Internal define to enable the refactored parts of Libxslt
+ * related to parsing.
+ */
+/* #define XSLT_REFACTORED_PARSING */
+
 /**
  * XSLT_MAX_SORT:
  *
@@ -150,6 +167,14 @@ struct _xsltDocument {
     int preproc;               /* pre-processing already done */
 };
 
+/*
+ * The in-memory structure corresponding to an XSLT Stylesheet.
+ * NOTE: most of the content is simply linked from the doc tree
+ *       structure, no specific allocation is made.
+ */
+typedef struct _xsltStylesheet xsltStylesheet;
+typedef xsltStylesheet *xsltStylesheetPtr;
+
 typedef struct _xsltTransformContext xsltTransformContext;
 typedef xsltTransformContext *xsltTransformContextPtr;
 
@@ -210,7 +235,8 @@ typedef enum {
     XSLT_FUNC_PARAM,
     XSLT_FUNC_VARIABLE,
     XSLT_FUNC_WHEN,
-    XSLT_FUNC_EXTENSION
+    XSLT_FUNC_EXTENSION,
+    XSLT_FUNC_OTHERWISE,
 } xsltStyleType;
 
 /**
@@ -224,14 +250,18 @@ typedef void (*xsltElemPreCompDeallocator) (xsltElemPreCompPtr comp);
 /**
  * xsltElemPreComp:
  *
- * The in-memory structure corresponding to element precomputed data,
- * designed to be extended by extension implementors.
+ * The basic structure for compiled items of the AST of the XSLT processor.
+ * This structure is also intended to be extended by extension implementors.
+ * TODO: This is somehow not nice, since it has a "free" field, which
+ *   derived stylesheet-structs do not have.
  */
 struct _xsltElemPreComp {
-    xsltElemPreCompPtr next;           /* chained list */
+    xsltElemPreCompPtr next;           /* next item in the global chained
+                                          list hold by xsltStylesheet. */
     xsltStyleType type;                        /* type of the element */
     xsltTransformFunction func;        /* handling function */
-    xmlNodePtr inst;                   /* the instruction */
+    xmlNodePtr inst;                   /* the node in the stylesheet's tree
+                                          corresponding to this item */
 
     /* end of common part */
     xsltElemPreCompDeallocator free;   /* the deallocator */
@@ -240,13 +270,668 @@ struct _xsltElemPreComp {
 /**
  * xsltStylePreComp:
  *
- * The in-memory structure corresponding to XSLT stylesheet constructs
- * precomputed data.
+ * The abstract basic structure for items of the
+ * AST of the XSLT processor.
+ * The AST includes:
+ * 1) compiled forms of XSLT instructions (xsl:if, xsl:attribute, etc.)
+ * 2) compiled forms of literal result elements
  */
 typedef struct _xsltStylePreComp xsltStylePreComp;
-
 typedef xsltStylePreComp *xsltStylePreCompPtr;
 
+/*************************
+ * Refactored structures *
+ *************************/
+#ifdef XSLT_REFACTORED
+
+typedef struct _xsltNsList xsltNsList;
+
+typedef xsltNsList *xsltNsListPtr;
+struct _xsltNsList {
+    xmlNsPtr *list;
+    int number;
+};
+
+#if 0
+/*
+ * TODO: xsltBasicItem is not used yet; maybe never will be used, since
+ * xsltElemPreCompPtr is acting as the base type for the compiled
+ * items of a stylesheet. It seems not practical to try to change
+ * this type to xsltBasicItemPtr, since xsltElemPreCompPtr is
+ * used already used too massively (e.g. xsltStylesheet->preComps) and
+ * for extension functions.
+ */
+/**
+ * xsltBasicItem:
+ *
+ * The basic structure for all items of the AST of the XSLT processor.
+ */
+typedef struct _xsltBasicItem xsltBasicItem;
+
+typedef xsltBasicItem *xsltBasicItemPtr;
+struct _xsltBasicItem {
+    xsltBasicASTItemPtr next;
+    xsltStyleType type;
+};
+#endif
+
+/**
+ * XSLT_ITEM_COMPATIBILITY_FIELDS:
+ * 
+ * Fields for API compatibility to the structure
+ * _xsltElemPreComp which is used for extension functions.
+ * TODO: Evaluate if we really need such a compatibility.
+ */
+#define XSLT_ITEM_COMPATIBILITY_FIELDS \
+    xsltElemPreCompPtr next;\
+    xsltStyleType type;\
+    xsltTransformFunction func;\
+    xmlNodePtr inst;
+
+/**
+ * XSLT_ITEM_NAVIGATION_FIELDS:
+ *
+ * Currently empty.
+ * TODO: It is intended to hold navigational fields in the future.
+ */
+#define XSLT_ITEM_NAVIGATION_FIELDS
+/*
+    xsltStylePreCompPtr parent;\
+    xsltStylePreCompPtr children;\
+    xsltStylePreCompPtr nextItem; 
+*/
+
+/**
+ * XSLT_ITEM_NSINSCOPE_FIELDS:
+ *
+ * The in-scope namespaces.
+ */
+#define XSLT_ITEM_NSINSCOPE_FIELDS xsltNsListPtr inScopeNS;
+
+/**
+ * XSLT_ITEM_COMMON_FIELDS:
+ *
+ * Common fields used for all items.
+ */
+#define XSLT_ITEM_COMMON_FIELDS \
+    XSLT_ITEM_COMPATIBILITY_FIELDS \
+    XSLT_ITEM_NAVIGATION_FIELDS \
+    XSLT_ITEM_NSINSCOPE_FIELDS
+
+/**
+ * _xsltStylePreComp: 
+ *
+ * The abstract basic structure for items of the XSLT processor.
+ * This includes:
+ * 1) compiled forms of XSLT instructions (e.g. xsl:if, xsl:attribute, etc.)
+ * 2) compiled forms of literal result elements
+ * 3) various properties for XSLT instructions (e.g. xsl:when,
+ *    xsl:with-param)
+ *
+ * REVISIT TODO: Keep this structure equal to the fields
+ *   defined by XSLT_ITEM_COMMON_FIELDS
+ */
+struct _xsltStylePreComp {
+    xsltElemPreCompPtr next;    /* next item in the global chained
+                                  list hold by xsltStylesheet */
+    xsltStyleType type;         /* type of the item */ 
+    xsltTransformFunction func; /* handling function */
+    xmlNodePtr inst;           /* the node in the stylesheet's tree
+                                  corresponding to this item. */
+    /* Currenlty to navigational fields. */
+    xsltNsListPtr inScopeNS;
+};
+
+/**
+ * xsltStyleBasicEmptyItem:
+ * 
+ * Abstract structure only used as a short-cut for
+ * XSLT items with no extra fields.
+ * NOTE that it is intended that this structure looks the same as
+ *  _xsltStylePreComp.
+ */
+typedef struct _xsltStyleBasicEmptyItem xsltStyleBasicEmptyItem;
+typedef xsltStyleBasicEmptyItem *xsltStyleBasicEmptyItemPtr;
+
+struct _xsltStyleBasicEmptyItem {
+    XSLT_ITEM_COMMON_FIELDS
+};
+
+/**
+ * xsltStyleBasicExpressionItem:
+ * 
+ * Abstract structure only used as a short-cut for
+ * XSLT items with just an expression.
+ */
+typedef struct _xsltStyleBasicExpressionItem xsltStyleBasicExpressionItem;
+typedef xsltStyleBasicExpressionItem *xsltStyleBasicExpressionItemPtr;
+
+struct _xsltStyleBasicExpressionItem {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *select; /* TODO: Change this to "expression". */
+    xmlXPathCompExprPtr comp; /* TODO: Change this to compExpr. */
+};
+
+/************************************************************************
+ *                                                                     *
+ * XSLT-instructions/declarations                                       *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * xsltStyleItemElement:
+ * 
+ * <!-- Category: instruction -->
+ * <xsl:element
+ *  name = { qname }
+ *  namespace = { uri-reference }
+ *  use-attribute-sets = qnames>
+ *  <!-- Content: template -->
+ * </xsl:element>
+ */
+typedef struct _xsltStyleItemElement xsltStyleItemElement;
+typedef xsltStyleItemElement *xsltStyleItemElementPtr;
+
+struct _xsltStyleItemElement {
+    XSLT_ITEM_COMMON_FIELDS 
+
+    const xmlChar *use;                /* copy, element */
+    int      has_use;          /* copy, element */
+    const xmlChar *name;       /* element, attribute, pi */
+    int      has_name;         /* element, attribute, pi */
+    const xmlChar *ns;         /* element */
+    int      has_ns;           /* element */
+
+};
+
+/**
+ * xsltStyleItemAttribute:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:attribute
+ *  name = { qname }
+ *  namespace = { uri-reference }>
+ *  <!-- Content: template -->
+ * </xsl:attribute>
+ */
+typedef struct _xsltStyleItemAttribute xsltStyleItemAttribute;
+typedef xsltStyleItemAttribute *xsltStyleItemAttributePtr;
+
+struct _xsltStyleItemAttribute {
+    XSLT_ITEM_COMMON_FIELDS
+    const xmlChar *name;       /* element, attribute, pi */
+    int      has_name;         /* element, attribute, pi */
+    const xmlChar *ns;         /* element  attribute */
+    int      has_ns;           /* element  attribute */
+};
+
+/**
+ * xsltStyleItemText:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:text
+ *  disable-output-escaping = "yes" | "no">
+ *  <!-- Content: #PCDATA -->
+ * </xsl:text>
+ */
+typedef struct _xsltStyleItemText xsltStyleItemText;
+typedef xsltStyleItemText *xsltStyleItemTextPtr;
+
+struct _xsltStyleItemText {
+    XSLT_ITEM_COMMON_FIELDS
+    int      noescape;         /* text */
+};
+
+/**
+ * xsltStyleItemComment:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:comment>
+ *  <!-- Content: template -->
+ * </xsl:comment>
+ */
+typedef xsltStyleBasicEmptyItem xsltStyleItemComment;
+typedef xsltStyleItemComment *xsltStyleItemCommentPtr;
+
+/**
+ * xsltStyleItemPI:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:processing-instruction
+ *  name = { ncname }>
+ *  <!-- Content: template -->
+ * </xsl:processing-instruction>
+ */
+typedef struct _xsltStyleItemPI xsltStyleItemPI;
+typedef xsltStyleItemPI *xsltStyleItemPIPtr;
+
+struct _xsltStyleItemPI {
+    XSLT_ITEM_COMMON_FIELDS
+    const xmlChar *name;
+    int      has_name;
+};
+
+/**
+ * xsltStyleItemApplyImports:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:apply-imports />
+ */
+typedef xsltStyleBasicEmptyItem xsltStyleItemApplyImports;
+typedef xsltStyleItemApplyImports *xsltStyleItemApplyImportsPtr;
+
+/**
+ * xsltStyleItemApplyTemplates:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:apply-templates
+ *  select = node-set-expression
+ *  mode = qname>
+ *  <!-- Content: (xsl:sort | xsl:with-param)* -->
+ * </xsl:apply-templates>
+ */
+typedef struct _xsltStyleItemApplyTemplates xsltStyleItemApplyTemplates;
+typedef xsltStyleItemApplyTemplates *xsltStyleItemApplyTemplatesPtr;
+
+struct _xsltStyleItemApplyTemplates {
+   XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *mode;       /* apply-templates */
+    const xmlChar *modeURI;    /* apply-templates */
+    const xmlChar *select;     /* sort, copy-of, value-of, apply-templates */
+    xmlXPathCompExprPtr comp;  /* a precompiled XPath expression */
+    /* TODO: with-params */
+};
+
+/**
+ * xsltStyleItemCallTemplate:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:call-template
+ *  name = qname>
+ *  <!-- Content: xsl:with-param* -->
+ * </xsl:call-template>
+ */
+typedef struct _xsltStyleItemCallTemplate xsltStyleItemCallTemplate;
+typedef xsltStyleItemCallTemplate *xsltStyleItemCallTemplatePtr;
+
+struct _xsltStyleItemCallTemplate {
+    XSLT_ITEM_COMMON_FIELDS
+
+    xsltTemplatePtr templ;     /* call-template */
+    const xmlChar *name;       /* element, attribute, pi */
+    int      has_name;         /* element, attribute, pi */
+    const xmlChar *ns;         /* element */
+    int      has_ns;           /* element */
+    /* TODO: with-params */
+};
+
+/**
+ * xsltStyleItemCopy:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:copy
+ *  use-attribute-sets = qnames>
+ *  <!-- Content: template -->
+ * </xsl:copy>
+ */
+typedef struct _xsltStyleItemCopy xsltStyleItemCopy;
+typedef xsltStyleItemCopy *xsltStyleItemCopyPtr;
+
+struct _xsltStyleItemCopy {
+   XSLT_ITEM_COMMON_FIELDS
+    const xmlChar *use;                /* copy, element */
+    int      has_use;          /* copy, element */    
+};
+
+/**
+ * xsltStyleItemIf:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:if
+ *  test = boolean-expression>
+ *  <!-- Content: template -->
+ * </xsl:if>
+ */
+typedef struct _xsltStyleItemIf xsltStyleItemIf;
+typedef xsltStyleItemIf *xsltStyleItemIfPtr;
+
+struct _xsltStyleItemIf {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *test;       /* if */
+    xmlXPathCompExprPtr comp;  /* a precompiled XPath expression */
+};
+
+
+/**
+ * xsltStyleItemCopyOf:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:copy-of
+ *  select = expression />
+ */
+typedef xsltStyleBasicExpressionItem xsltStyleItemCopyOf;
+typedef xsltStyleItemCopyOf *xsltStyleItemCopyOfPtr;
+
+/**
+ * xsltStyleItemValueOf:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:value-of
+ *  select = string-expression
+ *  disable-output-escaping = "yes" | "no" />
+ */
+typedef struct _xsltStyleItemValueOf xsltStyleItemValueOf;
+typedef xsltStyleItemValueOf *xsltStyleItemValueOfPtr;
+
+struct _xsltStyleItemValueOf {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *select;
+    xmlXPathCompExprPtr comp;  /* a precompiled XPath expression */
+    int      noescape;
+};
+
+/**
+ * xsltStyleItemNumber:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:number
+ *  level = "single" | "multiple" | "any"
+ *  count = pattern
+ *  from = pattern
+ *  value = number-expression
+ *  format = { string }
+ *  lang = { nmtoken }
+ *  letter-value = { "alphabetic" | "traditional" }
+ *  grouping-separator = { char }
+ *  grouping-size = { number } />
+ */
+typedef struct _xsltStyleItemNumber xsltStyleItemNumber;
+typedef xsltStyleItemNumber *xsltStyleItemNumberPtr;
+
+struct _xsltStyleItemNumber {
+    XSLT_ITEM_COMMON_FIELDS
+    xsltNumberData numdata;    /* number */
+};
+
+/**
+ * xsltStyleItemChoose:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:choose>
+ *  <!-- Content: (xsl:when+, xsl:otherwise?) -->
+ * </xsl:choose>
+ */
+typedef xsltStyleBasicEmptyItem xsltStyleItemChoose;
+typedef xsltStyleItemChoose *xsltStyleItemChoosePtr;
+
+/**
+ * xsltStyleItemFallback:
+ *
+ * <!-- Category: instruction -->
+ *  <xsl:fallback>
+ *  <!-- Content: template -->
+ * </xsl:fallback>
+ */
+typedef xsltStyleBasicEmptyItem xsltStyleItemFallback;
+typedef xsltStyleItemFallback *xsltStyleItemFallbackPtr;
+
+/**
+ * xsltStyleItemForEach:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:for-each
+ *   select = node-set-expression>
+ *   <!-- Content: (xsl:sort*, template) -->
+ * </xsl:for-each>
+ */
+typedef xsltStyleBasicExpressionItem xsltStyleItemForEach;
+typedef xsltStyleItemForEach *xsltStyleItemForEachPtr;
+
+/**
+ * xsltStyleItemMessage:
+ *
+ * <!-- Category: instruction -->
+ * <xsl:message
+ *   terminate = "yes" | "no">
+ *   <!-- Content: template -->
+ * </xsl:message>
+ */
+typedef struct _xsltStyleItemMessage xsltStyleItemMessage;
+typedef xsltStyleItemMessage *xsltStyleItemMessagePtr;
+
+struct _xsltStyleItemMessage {
+    XSLT_ITEM_COMMON_FIELDS    
+    int terminate;
+};
+
+/**
+ * xsltStyleItemDocument:
+ *
+ * NOTE: This is not an instruction of XSLT 1.0.
+ */
+typedef struct _xsltStyleItemDocument xsltStyleItemDocument;
+typedef xsltStyleItemDocument *xsltStyleItemDocumentPtr;
+
+struct _xsltStyleItemDocument {
+    XSLT_ITEM_COMMON_FIELDS
+    int      ver11;            /* assigned: in xsltDocumentComp;
+                                  read: nowhere;
+                                  TODO: Check if we need. */
+    const xmlChar *filename;   /* document URL */
+    int has_filename;
+};   
+
+/************************************************************************
+ *                                                                     *
+ * Non-instructions (actually properties of instructions/declarations)  *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * xsltStyleBasicItemVariable:
+ *
+ * Basic struct for xsl:variable, xsl:param and xsl:with-param.
+ * It's currently important to have equal fields, since
+ * xsltParseStylesheetCallerParam() is used with xsl:with-param from
+ * the xslt side and with xsl:param from the exslt side (in
+ * exsltFuncFunctionFunction()).
+ *
+ * FUTURE NOTE: In XSLT 2.0 xsl:param, xsl:variable and xsl:with-param
+ *   have additional different fields.
+ */
+typedef struct _xsltStyleBasicItemVariable xsltStyleBasicItemVariable;
+typedef xsltStyleBasicItemVariable *xsltStyleBasicItemVariablePtr;
+
+struct _xsltStyleBasicItemVariable {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *select;
+    xmlXPathCompExprPtr comp;
+
+    const xmlChar *name;
+    int      has_name;
+    const xmlChar *ns;
+    int      has_ns;
+};
+
+/**
+ * xsltStyleItemVariable:
+ *
+ * <!-- Category: top-level-element -->
+ * <xsl:param
+ *   name = qname
+ *   select = expression>
+ *   <!-- Content: template -->
+ * </xsl:param>
+ */
+typedef xsltStyleBasicItemVariable xsltStyleItemVariable;
+typedef xsltStyleItemVariable *xsltStyleItemVariablePtr;
+
+/**
+ * xsltStyleItemParam:
+ *
+ * <!-- Category: top-level-element -->
+ * <xsl:param
+ *   name = qname
+ *   select = expression>
+ *   <!-- Content: template -->
+ * </xsl:param>
+ */
+typedef xsltStyleBasicItemVariable xsltStyleItemParam;
+typedef xsltStyleItemParam *xsltStyleItemParamPtr;
+
+/**
+ * xsltStyleItemWithParam:
+ *
+ * <xsl:with-param
+ *  name = qname
+ *  select = expression>
+ *  <!-- Content: template -->
+ * </xsl:with-param>
+ */
+typedef xsltStyleBasicItemVariable xsltStyleItemWithParam;
+typedef xsltStyleItemWithParam *xsltStyleItemWithParamPtr;
+
+/**
+ * xsltStyleItemSort:
+ *
+ * Reflects the XSLT xsl:sort item.
+ * Allowed parents: xsl:apply-templates, xsl:for-each
+ * <xsl:sort
+ *   select = string-expression
+ *   lang = { nmtoken }
+ *   data-type = { "text" | "number" | qname-but-not-ncname }
+ *   order = { "ascending" | "descending" }
+ *   case-order = { "upper-first" | "lower-first" } />
+ */
+typedef struct _xsltStyleItemSort xsltStyleItemSort;
+typedef xsltStyleItemSort *xsltStyleItemSortPtr;
+
+struct _xsltStyleItemSort {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *stype;       /* sort */
+    int      has_stype;                /* sort */
+    int      number;           /* sort */
+    const xmlChar *order;      /* sort */
+    int      has_order;                /* sort */
+    int      descending;       /* sort */
+    const xmlChar *lang;       /* sort */
+    int      has_lang;         /* sort */
+    const xmlChar *case_order; /* sort */
+    int      lower_first;      /* sort */
+
+    const xmlChar *use;
+    int      has_use;
+
+    const xmlChar *select;     /* sort, copy-of, value-of, apply-templates */
+
+    xmlXPathCompExprPtr comp;  /* a precompiled XPath expression */
+};
+
+
+/**
+ * xsltStyleItemWhen:
+ * 
+ * <xsl:when
+ *   test = boolean-expression>
+ *   <!-- Content: template -->
+ * </xsl:when>
+ * Allowed parent: xsl:choose
+ */
+typedef struct _xsltStyleItemWhen xsltStyleItemWhen;
+typedef xsltStyleItemWhen *xsltStyleItemWhenPtr;
+
+struct _xsltStyleItemWhen {
+    XSLT_ITEM_COMMON_FIELDS
+
+    const xmlChar *test;
+    xmlXPathCompExprPtr comp;
+};
+
+/**
+ * xsltStyleItemOtherwise:
+ *
+ * Allowed parent: xsl:choose
+ * <xsl:otherwise>
+ *   <!-- Content: template -->
+ * </xsl:otherwise>
+ */
+typedef struct _xsltStyleItemOtherwise xsltStyleItemOtherwise;
+typedef xsltStyleItemOtherwise *xsltStyleItemOtherwisePtr;
+
+struct _xsltStyleItemOtherwise {
+    XSLT_ITEM_COMMON_FIELDS
+};
+
+/*
+ * Literal result elements.
+ * TODO: Not used yet.
+ */
+typedef struct _xsltStyleItemLRE xsltStyleItemLRE;
+typedef xsltStyleItemLRE *xsltStyleItemLREPtr;
+struct _xsltStyleItemLRE {
+    XSLT_ITEM_COMMON_FIELDS
+};
+
+/************************************************************************
+ *                                                                     *
+ *  Compile-time structures for *internal* use only                     *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * xsltCompilerNodeInfo:
+ *
+ * Per-node information during compile-time.
+ */
+typedef struct _xsltCompilerNodeInfo xsltCompilerNodeInfo;
+typedef xsltCompilerNodeInfo *xsltCompilerNodeInfoPtr;
+struct _xsltCompilerNodeInfo {
+    xsltCompilerNodeInfoPtr next;
+    xsltCompilerNodeInfoPtr prev;
+    xmlNodePtr node;
+    int depth;
+    xsltNsListPtr inScopeNS; /* The in-scope namespaces for the current
+                                position in the node-tree */
+    xsltTemplatePtr templ;   /* The owning template */
+    xsltElemPreCompPtr item; /* The compiled information */
+};
+
+#define XSLT_CCTXT(style) ((xsltCompilerCtxtPtr) style->compCtxt)
+
+typedef struct _xsltCompilerCtxt xsltCompilerCtxt;
+typedef xsltCompilerCtxt *xsltCompilerCtxtPtr;
+struct _xsltCompilerCtxt {
+    void *errorCtxt;             /* user specific error context */
+    int warnings;              /* TODO: number of warnings found at
+                                   compilation */
+    int errors;                        /* TODO: number of errors found at
+                                   compilation */
+    xsltStylesheetPtr sheet;
+    /* TODO: structured/unstructured error contexts. */
+    int depth; /* TODO: current depth in the stylesheets node-tree */
+    
+    xsltCompilerNodeInfoPtr inode;
+    xsltCompilerNodeInfoPtr inodeList;
+    xsltCompilerNodeInfoPtr inodeLast;
+};   
+
+#else /* XSLT_REFACTORED */
+/*
+* The old structures before refactoring.
+*/
+
+/**
+ * _xsltStylePreComp:
+ *
+ * The in-memory structure corresponding to XSLT stylesheet constructs
+ * precomputed data.
+ */
 struct _xsltStylePreComp {
     xsltElemPreCompPtr next;   /* chained list */
     xsltStyleType type;                /* type of the element */
@@ -298,11 +983,12 @@ struct _xsltStylePreComp {
     int nsNr;                  /* the number of namespaces in scope */
 };
 
+#endif /* XSLT_REFACTORED */
+
 /*
  * The in-memory structure corresponding to an XSLT Variable
  * or Param.
  */
-
 typedef struct _xsltStackElem xsltStackElem;
 typedef xsltStackElem *xsltStackElemPtr;
 struct _xsltStackElem {
@@ -317,12 +1003,10 @@ struct _xsltStackElem {
 };
 
 /*
- * The in-memory structure corresponding to an XSLT Stylesheet.
- * NOTE: most of the content is simply linked from the doc tree
- *       structure, no specific allocation is made.
+ * TODO: We need a field to anchor an stylesheet compilation context, since,
+ *   due to historical reasons, various compile-time function take only the
+ *   stylesheet as argument and not a compilation context.
  */
-typedef struct _xsltStylesheet xsltStylesheet;
-typedef xsltStylesheet *xsltStylesheetPtr;
 struct _xsltStylesheet {
     /*
      * The stylesheet import relation is kept as a tree.
@@ -451,6 +1135,16 @@ struct _xsltStylesheet {
      * Literal Result Element as Stylesheet c.f. section 2.3
      */
     int literal_result;
+#ifdef XSLT_REFACTORED
+    /*
+    * Compilation context used during compile-time.
+    */
+    void * compCtxt;
+    /*
+    * Namespace lists.
+    */
+    void *inScopeNamespaces;    
+#endif    
 };
 
 /*
@@ -695,6 +1389,17 @@ XSLTPUBFUN xmlChar * XSLTCALL
 XSLTPUBFUN void XSLTCALL
                        xsltFreeAVTList         (void *avt);
 
+/************************************************************************
+ *                                                                     *
+ *  Compile-time functions for *internal* use only                      *
+ *                                                                     *
+ ************************************************************************/
+
+#ifdef XSLT_REFACTORED
+XSLTPUBFUN xsltNsListPtr XSLTCALL
+                       xsltCompilerGetInScopeNSInfo(xsltCompilerCtxtPtr cctxt,
+                                                    xmlNodePtr node);
+#endif /* XSLT_REFACTORED */
 /*
  * Extra function for successful xsltCleanupGlobals / xsltInit sequence.
  */
index 0700bf5..f7ee731 100644 (file)
@@ -300,6 +300,134 @@ error:
     return(-1);
 }
 
+#ifdef XSLT_REFACTORED
+
+/**
+ * xsltPointerListCreate:
+ *
+ * Creates an xsltPointerList structure.
+ *
+ * Returns a xsltPointerList structure or NULL in case of an error.
+ */
+xsltPointerListPtr
+xsltPointerListCreate(void)
+{
+    xsltPointerListPtr ret;
+
+    ret = xmlMalloc(sizeof(xsltPointerList));
+    if (ret == NULL) {
+       xsltGenericError(xsltGenericErrorContext,
+            "xsltPointerListCreate: memory allocation failure.\n");
+       return (NULL);
+    }
+    memset(ret, 0, sizeof(xsltPointerList));
+    return (ret);
+}
+
+/**
+ * xsltPointerListFree:
+ *
+ * Frees the xsltPointerList structure. This does not free
+ * the content of the list.
+ */
+void
+xsltPointerListFree(xsltPointerListPtr list)
+{
+    if (list == NULL)
+       return;
+    if (list->items != NULL)
+       xmlFree(list->items);
+    xmlFree(list);
+}
+
+/**
+ * xsltPointerListFree:
+ *
+ * Resets the list, but does not free the allocated array
+ * and does not free the content of the list.
+ */
+void
+xsltPointerListClear(xsltPointerListPtr list)
+{
+    if (list->items != NULL) {
+       xmlFree(list->items);
+       list->items = NULL;
+    }
+    list->number = 0;
+    list->size = 0;
+}
+
+/**
+ * xsltPointerListAdd:
+ *
+ * Adds an item to the list.
+ *
+ * Returns the position of the added item in the list or
+ *         -1 in case of an error.
+ */
+int
+xsltPointerListAdd(xsltPointerListPtr list, void *item)
+{
+    if (list->items == NULL) {
+       list->items = (void **) xmlMalloc(
+           20 * sizeof(void *));
+       if (list->items == NULL) {
+           xsltGenericError(xsltGenericErrorContext,
+            "xsltPointerListAdd: memory allocation failure.\n");
+           return(-1);
+       }
+       list->number = 0;
+       list->size = 20;
+    } else if (list->size <= list->number) {
+       list->size *= 2;
+       list->items = (void **) xmlRealloc(list->items,
+           list->size * sizeof(void *));
+       if (list->items == NULL) {
+           xsltGenericError(xsltGenericErrorContext,
+            "xsltPointerListAdd: memory re-allocation failure.\n");
+           list->size = 0;
+           return(-1);
+       }
+    }
+    list->items[list->number++] = item;
+    return(0);
+}
+
+#if 0 /* TODO: Not used yet. Enable if ever needed. */
+static int
+xsltPointerListAddSize(xsltPointerListPtr list,
+                      int initialSize,
+                      void *item)
+{
+    if (list->items == NULL) {
+       if (initialSize <= 0)
+           initialSize = 1;
+       list->items = (void **) xmlMalloc(
+           initialSize * sizeof(void *));
+       if (list->items == NULL) {
+           xsltGenericError(xsltGenericErrorContext,
+            "xsltPointerListAddSize: memory allocation failure.\n");
+           return(-1);
+       }
+       list->number = 0;
+       list->size = initialSize;
+    } else if (list->size <= list->number) {
+       list->size *= 2;
+       list->items = (void **) xmlRealloc(list->items,
+           list->size * sizeof(void *));
+       if (list->items == NULL) {
+           xsltGenericError(xsltGenericErrorContext,
+            "xsltPointerListAddSize: memory re-allocation failure.\n");
+           list->size = 0;
+           return(-1);
+       }
+    }
+    list->items[list->number++] = item;
+    return(0);
+}
+#endif
+
+#endif /* XSLT_REFACTORED */
 
 /************************************************************************
  *                                                                     *
@@ -824,12 +952,16 @@ xsltDocumentSortFunction(xmlNodeSetPtr list) {
  */
 xmlXPathObjectPtr *
 xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemSortPtr comp;
+#else
+    xsltStylePreCompPtr comp;
+#endif
     xmlXPathObjectPtr *results = NULL;
     xmlNodeSetPtr list = NULL;
     xmlXPathObjectPtr res;
     int len = 0;
-    int i;
-    xsltStylePreCompPtr comp;
+    int i;    
     xmlNodePtr oldNode;
     xmlNodePtr oldInst;
     int        oldPos, oldSize ;
@@ -875,8 +1007,18 @@ xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
        ctxt->xpathCtxt->proximityPosition = i + 1;
        ctxt->node = list->nodeTab[i];
        ctxt->xpathCtxt->node = ctxt->node;
+#ifdef XSLT_REFACTORED
+       if (comp->inScopeNS != NULL) {
+           ctxt->xpathCtxt->namespaces = comp->inScopeNS->list;
+           ctxt->xpathCtxt->nsNr = comp->inScopeNS->number;
+       } else {
+           ctxt->xpathCtxt->namespaces = NULL;
+           ctxt->xpathCtxt->nsNr = 0;
+       }
+#else
        ctxt->xpathCtxt->namespaces = comp->nsList;
        ctxt->xpathCtxt->nsNr = comp->nsNr;
+#endif
        res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
        if (res != NULL) {
            if (res->type != XPATH_STRING)
@@ -932,6 +1074,11 @@ xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
 void   
 xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
                   int nbsorts) {
+#ifdef XSLT_REFACTORED
+    xsltStyleItemSortPtr comp;
+#else
+    xsltStylePreCompPtr comp;
+#endif
     xmlXPathObjectPtr *resultsTab[XSLT_MAX_SORT];
     xmlXPathObjectPtr *results = NULL, *res;
     xmlNodeSetPtr list = NULL;
@@ -941,8 +1088,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
     int tst;
     int depth;
     xmlNodePtr node;
-    xmlXPathObjectPtr tmp;
-    xsltStylePreCompPtr comp;
+    xmlXPathObjectPtr tmp;    
     int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT];
 
     if ((ctxt == NULL) || (sorts == NULL) || (nbsorts <= 0) ||
index 058d143..c4e3ae9 100644 (file)
@@ -298,6 +298,31 @@ XSLTPUBFUN int XSLTCALL
 XSLTPUBFUN void XSLTCALL               
                xslDropCall                     (void);
 
+#ifdef XSLT_REFACTORED
+/**
+ * xsltPointerList:
+ *
+ * Pointer-list for various purposes.
+ */
+typedef struct _xsltPointerList xsltPointerList;
+typedef xsltPointerList *xsltPointerListPtr;
+struct _xsltPointerList {
+    void **items;
+    int number;
+    int size;
+};
+
+XSLTPUBFUN xsltPointerListPtr XSLTCALL
+               xsltPointerListCreate           (void);
+XSLTPUBFUN void XSLTCALL
+               xsltPointerListFree             (xsltPointerListPtr list);
+XSLTPUBFUN void XSLTCALL
+               xsltPointerListClear            (xsltPointerListPtr list);
+XSLTPUBFUN int XSLTCALL
+               xsltPointerListAdd              (xsltPointerListPtr list,
+                                                void *item);
+#endif /* XSLT_REFACTOR */
+
 #ifdef __cplusplus
 }
 #endif