From bdcd6346ff23d5c1cfe23be8b6bda0917ef1aa2f Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 16 Apr 2001 14:10:45 +0000 Subject: - libxslt/keys.c libxslt/preproc.c libxslt/templates.c libxslt/transform.c libxslt/variables.c libxslt/xsltInternals.h: fixed for the most part the namespace handling problem in XPath expression computations. - test/doc/ tests/general: added bug 5 and 6 Daniel --- ChangeLog | 8 + TODO | 27 ++- libxslt/keys.c | 5 +- libxslt/preproc.c | 19 ++ libxslt/templates.c | 6 + libxslt/transform.c | 16 +- libxslt/variables.c | 5 +- libxslt/xsltInternals.h | 2 + tests/XSLTMark/summarize.out | 6 +- tests/docs/bug-5-.xml | 475 +++++++++++++++++++++++++++++++++++++++++++ tests/docs/bug-6-.xml | 6 + tests/general/bug-5-.out | 126 ++++++++++++ tests/general/bug-5-.xsl | 158 ++++++++++++++ tests/general/bug-6-.out | 4 + tests/general/bug-6-.xsl | 31 +++ 15 files changed, 877 insertions(+), 17 deletions(-) create mode 100644 tests/docs/bug-5-.xml create mode 100644 tests/docs/bug-6-.xml create mode 100644 tests/general/bug-5-.out create mode 100644 tests/general/bug-5-.xsl create mode 100644 tests/general/bug-6-.out create mode 100644 tests/general/bug-6-.xsl diff --git a/ChangeLog b/ChangeLog index af7cdcb1..20d7c814 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Apr 17 10:10:56 CEST 2001 Daniel Veillard + + * libxslt/keys.c libxslt/preproc.c libxslt/templates.c + libxslt/transform.c libxslt/variables.c libxslt/xsltInternals.h: + fixed for the most part the namespace handling problem in XPath + expression computations. + * test/doc/ tests/general: added bug 5 and 6 + Thu Apr 12 14:40:22 CEST 2001 Daniel Veillard * libxslt/xslt.c: applied William M. Brack patch fixing the diff --git a/TODO b/TODO index 25883ca1..8c4dfcf6 100644 --- a/TODO +++ b/TODO @@ -4,10 +4,6 @@ * * ******** -Leak: - - find and fix memleak in xmlspec - => this is new ... - Doc: - manpage and doc for xsltproc @@ -19,17 +15,14 @@ Design: be a bit ugly ... Embedding Stylesheets: - - example in 2.7 would force to validate + - example in 2.7 would force to validate, we do it by default now Import: -Extra functions: - -> document() should not be a problem since Result Tree Fragments are - implemented - => started, incomplete ID and Key support: - -> Id should be simple, key will probably requires some hash tables. + -> done but namespace support in keys is not defined + -> make sure keys are recomputed on new document input Pattern tester: -> try to optimize for ID scan and tests. @@ -44,7 +37,8 @@ Error handling: -> catch recursion end of 5.4 ... Support Attribute value templates: - -> optimization by checking their existence at stylesheet parse time. + -> namespace support for attribute value templates is not done, need + a small API redesign Sorting: -> add support for imbricated sorts @@ -57,6 +51,14 @@ Sorting: * * ******** +ID and Key support: + -> Done + +Extra functions: + -> document() should not be a problem since Result Tree Fragments are + implemented + => Done + Templates: -> check the built-in template rule for attributes -> make sure @xxx matches are applied @@ -83,6 +85,9 @@ Support Attribute value templates: to handle most of it at the stylesheet parse time ... => Done for the most part need to check all attributes in XSLT constructs using them and use the dedicated readin function. + -> optimization by checking their existence at stylesheet parse time. + => done when building the preproc function + Separate util module: -> macros, config, verbosity ? diff --git a/libxslt/keys.c b/libxslt/keys.c index f7ce9233..0fd61f54 100644 --- a/libxslt/keys.c +++ b/libxslt/keys.c @@ -316,9 +316,12 @@ xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc, if (comp == NULL) goto error; ctxt->document = doc; - ctxt->node = (xmlNodePtr) doc->doc; ctxt->xpathCtxt->node = (xmlNodePtr) doc->doc; position = ctxt->xpathCtxt->proximityPosition; + ctxt->node = (xmlNodePtr) doc->doc; + /* TODO : clarify the use of namespaces in keys evaluation */ + ctxt->xpathCtxt->namespaces = NULL; + ctxt->xpathCtxt->nsNr = 0; res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); ctxt->xpathCtxt->proximityPosition = position; xmlXPathFreeCompExpr(comp); diff --git a/libxslt/preproc.c b/libxslt/preproc.c index 4f2f9f6d..e0f08cb7 100644 --- a/libxslt/preproc.c +++ b/libxslt/preproc.c @@ -160,6 +160,8 @@ xsltFreeStylePreComp(xsltStylePreCompPtr comp) { xmlFree(comp->numdata.format); if (comp->comp != NULL) xmlXPathFreeCompExpr(comp->comp); + if (comp->nsList != NULL) + xmlFree(comp->nsList); memset(comp, -1, sizeof(xsltStylePreComp)); @@ -921,6 +923,8 @@ xsltStylePreCompute(xsltTransformContextPtr ctxt, xmlNodePtr inst) { if (inst->_private != NULL) return; if (IS_XSLT_ELEM(inst)) { + xsltStylePreCompPtr cur; + if (IS_XSLT_NAME(inst, "apply-templates")) { xsltApplyTemplatesComp(ctxt, inst); } else if (IS_XSLT_NAME(inst, "value-of")) { @@ -968,6 +972,21 @@ xsltStylePreCompute(xsltTransformContextPtr ctxt, xmlNodePtr inst) { xsltGenericError(xsltGenericDebugContext, "xsltStylePreCompute: unknown xslt:%s\n", inst->name); } + /* + * Add the namespace lookup here, this code can be shared by + * all precomputations. + */ + cur = inst->_private; + if (cur != NULL) { + int i = 0; + + cur->nsList = xmlGetNsList(inst->doc, inst); + if (cur->nsList != NULL) { + while (cur->nsList[i] != NULL) + i++; + } + cur->nsNr = i; + } } else { if (IS_XSLT_NAME(inst, "document")) { xsltDocumentComp(ctxt, inst); diff --git a/libxslt/templates.c b/libxslt/templates.c index b038ae73..96a54fa7 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -54,6 +54,9 @@ xsltEvalXPathPredicate(xsltTransformContextPtr ctxt, position = ctxt->xpathCtxt->proximityPosition; ctxt->xpathCtxt->node = ctxt->node; + /* TODO: do we need to propagate the namespaces here ? */ + ctxt->xpathCtxt->namespaces = NULL; + ctxt->xpathCtxt->nsNr = 0; res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); ctxt->xpathCtxt->proximityPosition = position; if (res != NULL) { @@ -89,6 +92,9 @@ xsltEvalXPathString(xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp) { xmlXPathObjectPtr res; ctxt->xpathCtxt->node = ctxt->node; + /* TODO: do we need to propagate the namespaces here ? */ + ctxt->xpathCtxt->namespaces = NULL; + ctxt->xpathCtxt->nsNr = 0; res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); if (res != NULL) { if (res->type != XPATH_STRING) diff --git a/libxslt/transform.c b/libxslt/transform.c index fabfc45a..60f319c0 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -1224,6 +1224,8 @@ xsltSort(xsltTransformContextPtr ctxt, xmlNodePtr node, ctxt->xpathCtxt->proximityPosition = i + 1; ctxt->node = list->nodeTab[i]; ctxt->xpathCtxt->node = ctxt->node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); if (res != NULL) { if (res->type != XPATH_STRING) @@ -1740,6 +1742,8 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node, oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->proximityPosition = oldProximityPosition; ctxt->xpathCtxt->contextSize = oldContextSize; @@ -1833,6 +1837,8 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->proximityPosition = oldProximityPosition; ctxt->xpathCtxt->contextSize = oldContextSize; @@ -2032,6 +2038,8 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node, oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldContextSize; ctxt->xpathCtxt->proximityPosition = oldProximityPosition; @@ -2241,6 +2249,8 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node, oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(xpathComp, ctxt->xpathCtxt); xmlXPathFreeCompExpr(xpathComp); ctxt->xpathCtxt->proximityPosition = oldProximityPosition; @@ -2340,6 +2350,8 @@ xsltIf(xsltTransformContextPtr ctxt, xmlNodePtr node, oldContextSize = ctxt->xpathCtxt->contextSize; oldProximityPosition = ctxt->xpathCtxt->proximityPosition; ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldContextSize; ctxt->xpathCtxt->proximityPosition = oldProximityPosition; @@ -2411,9 +2423,11 @@ xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr node, "xsltForEach: select %s\n", comp->select); #endif - ctxt->xpathCtxt->node = node; oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; + ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->namespaces = comp->nsList; + ctxt->xpathCtxt->nsNr = comp->nsNr; res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldContextSize; ctxt->xpathCtxt->proximityPosition = oldProximityPosition; diff --git a/libxslt/variables.c b/libxslt/variables.c index 172de6ec..1e5c9e31 100644 --- a/libxslt/variables.c +++ b/libxslt/variables.c @@ -259,9 +259,12 @@ int oldProximityPosition, oldContextSize; comp = xmlXPathCompile(elem->select); if (comp == NULL) return(-1); - ctxt->xpathCtxt->node = (xmlNodePtr) ctxt->node; oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; + ctxt->xpathCtxt->node = (xmlNodePtr) ctxt->node; + /* TODO: do we need to propagate the namespaces here ? */ + ctxt->xpathCtxt->namespaces = NULL; + ctxt->xpathCtxt->nsNr = 0; result = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldContextSize; ctxt->xpathCtxt->proximityPosition = oldProximityPosition; diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 46035a3f..bc730c08 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -260,6 +260,8 @@ struct _xsltStylePreComp { xsltNumberData numdata; /* number */ xmlXPathCompExprPtr comp; /* a precompiled XPath expression */ + xmlNsPtr *nsList; /* the namespaces in scope */ + int nsNr; /* the number of namespaces in scope */ }; /* diff --git a/tests/XSLTMark/summarize.out b/tests/XSLTMark/summarize.out index 52bce4c1..cb6e2aab 100644 --- a/tests/XSLTMark/summarize.out +++ b/tests/XSLTMark/summarize.out @@ -3,7 +3,7 @@ 100 elements, 137 text nodes, 131 attributes. - Recognized as xslt stylesheet:0 templates, - 0 variables, - 0 value-of's, + Recognized as xslt stylesheet:7 templates, + 1 variables, + 2 value-of's, diff --git a/tests/docs/bug-5-.xml b/tests/docs/bug-5-.xml new file mode 100644 index 00000000..f5a34ecd --- /dev/null +++ b/tests/docs/bug-5-.xml @@ -0,0 +1,475 @@ + + +Wed Apr 4 23:00:55 2001 GMT + + + + +1 +Apple +Non-Recurring +Birch +0 +50 +PICK + + + + + + +6 +Apple +Non-Recurring +Pine +0 +0 +EAT + + +60 +Apple +Non-Recurring +Elm +0 +0 +EAT + + +2 +Apple +Non-Recurring +Birch +0 +0 +EAT + + + + + + +7 +Apple +Recurring +Pine +19250 +16.61 +SQUEEZE + + +96 +Apple +Recurring +Elm +220000 +11.76 +SQUEEZE + + +6 +Apple +Recurring +Birch +16500 +7.16 +SQUEEZE + + + + + + + + +34 +Orange +Non-Recurring +Pine +0 +1420 +PICK + + +1 +Orange +Non-Recurring +Almond +0 +25 +PICK + + +8 +Orange +Non-Recurring +Birch +0 +300 +PICK + + +186 +Orange +Non-Recurring +Elm +0 +6555 +PICK + + + + +36 +Orange +Recurring +Pine +171000 +221.3 +PICK + + +240 +Orange +Recurring +Elm +950000 +1412.34 +PICK + + +8 +Orange +Recurring +Birch +38000 +30.84 +PICK + + + + + + +34 +Orange +Non-Recurring +Pine +0 +0 +EAT + + +1 +Orange +Non-Recurring +Almond +0 +0 +EAT + + +62 +Orange +Non-Recurring +Elm +0 +0 +EAT + + +4 +Orange +Non-Recurring +Birch +0 +0 +EAT + + + + +8 +Orange +Recurring +Birch +0 +0 +EAT + + + + + + +36 +Orange +Recurring +Pine +171000 +221.3 +SQUEEZE + + +80 +Orange +Recurring +Elm +380000 +470.78 +SQUEEZE + + +4 +Orange +Recurring +Birch +19000 +15.42 +SQUEEZE + + +3 +Orange +Recurring +Almond +14250 +23.25 +SQUEEZE + + + + + + + + +2 +Banana +Non-Recurring +Elm +0 +100 +PICK + + + + +1 +Banana +Recurring +Pine +12250 +12.25 +PICK + + +6 +Banana +Recurring +Elm +73500 +78.4 +PICK + + +1 +Banana +Recurring +Almond +12250 +12.25 +PICK + + + + + + +1 +Banana +Recurring +Almond +12250 +0 +EAT + + + + + + + + +1 +Nectarine +Recurring +Pine +5950 +-5.95 +SQUEEZE + + + + + + + + +1 +Pineapple +Non-Recurring +Pine +0 +50 +PICK + + + + +2 +Pineapple +Recurring +Pine +17500 +8.75 +PICK + + +1 +Pineapple +Recurring +Birch +6250 +10 +PICK + + + + + + +1 +Pineapple +Non-Recurring +Elm +0 +0 +EAT + + + + + + +2 +Pineapple +Recurring +Elm +12500 +4.38 +SQUEEZE + + + + + + + + +1 +Coconut +Recurring +Elm +13750 +17.87 +PICK + + + + + + + + +1 +Guava +Recurring +Pine +14995 +-19.49 +SQUEEZE + + + + + + + + +1 +Pear +Recurring +Pine +29995 +38.99 +PICK + + + + + + + + +17 +Raisin +Non-Recurring +Oak +0 +0 +EAT + + + + + + +15 +Raisin +Recurring +Oak +299925 +227.95 +SQUEEZE + + + + + + + + +1 +Fig +Non-Recurring +Oak +0 +50 +PICK + + + + +2 +Fig +Recurring +Oak +74990 +86.24 +PICK + + + + + diff --git a/tests/docs/bug-6-.xml b/tests/docs/bug-6-.xml new file mode 100644 index 00000000..e0222812 --- /dev/null +++ b/tests/docs/bug-6-.xml @@ -0,0 +1,6 @@ + + + + Title of my document + + diff --git a/tests/general/bug-5-.out b/tests/general/bug-5-.out new file mode 100644 index 00000000..b6dd1255 --- /dev/null +++ b/tests/general/bug-5-.out @@ -0,0 +1,126 @@ + +Churn by Product

Churn by Product

+ Run Date: Wed Apr 4 23:00:55 2001 GMT
+ Parameters: +
Legend
Product
Action
Non-Recurring
Recurring
AppleProj. Rev: 255750Actual Rev: 85.53
PICKProj. Rev: 0Act. Rev: 50
EATProj. Rev: 0Act. Rev: 0
SQUEEZEProj. Rev: 255750Act. Rev: 35.53
OrangeProj. Rev: 1743250Actual Rev: 10695.229999999
PICKProj. Rev: 1159000Act. Rev: 9964.479999999
EATProj. Rev: 0Act. Rev: 0
SQUEEZEProj. Rev: 584250Act. Rev: 730.749999999
BananaProj. Rev: 110250Actual Rev: 202.9
PICKProj. Rev: 98000Act. Rev: 202.9
EATProj. Rev: 12250Act. Rev: 0
NectarineProj. Rev: 5950Actual Rev: -5.95
SQUEEZEProj. Rev: 5950Act. Rev: -5.95
PineappleProj. Rev: 36250Actual Rev: 73.129999999
PICKProj. Rev: 23750Act. Rev: 68.75
EATProj. Rev: 0Act. Rev: 0
SQUEEZEProj. Rev: 12500Act. Rev: 4.379999999
CoconutProj. Rev: 13750Actual Rev: 17.87
PICKProj. Rev: 13750Act. Rev: 17.87
GuavaProj. Rev: 14995Actual Rev: -19.489999999
SQUEEZEProj. Rev: 14995Act. Rev: -19.489999999
PearProj. Rev: 29995Actual Rev: 38.99
PICKProj. Rev: 29995Act. Rev: 38.99
RaisinProj. Rev: 299925Actual Rev: 227.949999999
EATProj. Rev: 0Act. Rev: 0
SQUEEZEProj. Rev: 299925Act. Rev: 227.949999999
FigProj. Rev: 74990Actual Rev: 136.24
PICKProj. Rev: 74990Act. Rev: 136.24
diff --git a/tests/general/bug-5-.xsl b/tests/general/bug-5-.xsl new file mode 100644 index 00000000..b0fe9f82 --- /dev/null +++ b/tests/general/bug-5-.xsl @@ -0,0 +1,158 @@ + + + + + + + Churn by Product + + + +

Churn by Product

+ + + + + +
+ Run Date:
+ Parameters: +
+ + + + + +
Legend
Product
Action
Non-Recurring
Recurring
+
+
+ + +
+ + +PROD + + + + Proj. Rev: + Actual Rev: + + + + +PROD + + + + + + + + + +ACT + + + + Proj. Rev: + Act. Rev: + + + + + + + + + + + +ACT + + + + + + + + + + + + RC + NR + + + + + + + + + + + + + + + + + + + + + RC + NR + + + + + +
Number: Proj. Rev: Act. Rev:
SegmentNumberProj. RevAct. Rev
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/tests/general/bug-6-.out b/tests/general/bug-6-.out new file mode 100644 index 00000000..e3f13ac3 --- /dev/null +++ b/tests/general/bug-6-.out @@ -0,0 +1,4 @@ + +Title of my document

Title of my document

+ +
diff --git a/tests/general/bug-6-.xsl b/tests/general/bug-6-.xsl new file mode 100644 index 00000000..33100d78 --- /dev/null +++ b/tests/general/bug-6-.xsl @@ -0,0 +1,31 @@ + + + + + + + + + <xsl:value-of select="my:document/my:name"/> + + + + + + + + +

+ +
+ +
+ + + + + +
-- cgit v1.2.3