OLD | NEW |
1 /* | 1 /* |
2 * transform.c: Implementation of the XSL Transformation 1.0 engine | 2 * transform.c: Implementation of the XSL Transformation 1.0 engine |
3 * transform part, i.e. applying a Stylesheet to a document | 3 * transform part, i.e. applying a Stylesheet to a document |
4 * | 4 * |
5 * References: | 5 * References: |
6 * http://www.w3.org/TR/1999/REC-xslt-19991116 | 6 * http://www.w3.org/TR/1999/REC-xslt-19991116 |
7 * | 7 * |
8 * Michael Kay "XSLT Programmer's Reference" pp 637-643 | 8 * Michael Kay "XSLT Programmer's Reference" pp 637-643 |
9 * Writing Multiple Output Files | 9 * Writing Multiple Output Files |
10 * | 10 * |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 331 } |
332 } | 332 } |
333 if (i == templ->templNr) { | 333 if (i == templ->templNr) { |
334 /* not found, add new one */ | 334 /* not found, add new one */ |
335 templ->templCalledTab[templ->templNr] = parent; | 335 templ->templCalledTab[templ->templNr] = parent; |
336 templ->templCountTab[templ->templNr] = 1; | 336 templ->templCountTab[templ->templNr] = 1; |
337 templ->templNr++; | 337 templ->templNr++; |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
| 341 /** |
| 342 * xsltPreCompEval: |
| 343 * @ctxt: transform context |
| 344 * @node: context node |
| 345 * @comp: precompiled expression |
| 346 * |
| 347 * Evaluate a precompiled XPath expression. |
| 348 */ |
| 349 static xmlXPathObjectPtr |
| 350 xsltPreCompEval(xsltTransformContextPtr ctxt, xmlNodePtr node, |
| 351 xsltStylePreCompPtr comp) { |
| 352 xmlXPathObjectPtr res; |
| 353 xmlXPathContextPtr xpctxt; |
| 354 xmlNodePtr oldXPContextNode; |
| 355 xmlNsPtr *oldXPNamespaces; |
| 356 int oldXPProximityPosition, oldXPContextSize, oldXPNsNr; |
| 357 |
| 358 xpctxt = ctxt->xpathCtxt; |
| 359 oldXPContextNode = xpctxt->node; |
| 360 oldXPProximityPosition = xpctxt->proximityPosition; |
| 361 oldXPContextSize = xpctxt->contextSize; |
| 362 oldXPNsNr = xpctxt->nsNr; |
| 363 oldXPNamespaces = xpctxt->namespaces; |
| 364 |
| 365 xpctxt->node = node; |
| 366 #ifdef XSLT_REFACTORED |
| 367 if (comp->inScopeNs != NULL) { |
| 368 xpctxt->namespaces = comp->inScopeNs->list; |
| 369 xpctxt->nsNr = comp->inScopeNs->xpathNumber; |
| 370 } else { |
| 371 xpctxt->namespaces = NULL; |
| 372 xpctxt->nsNr = 0; |
| 373 } |
| 374 #else |
| 375 xpctxt->namespaces = comp->nsList; |
| 376 xpctxt->nsNr = comp->nsNr; |
| 377 #endif |
| 378 |
| 379 res = xmlXPathCompiledEval(comp->comp, xpctxt); |
| 380 |
| 381 xpctxt->node = oldXPContextNode; |
| 382 xpctxt->proximityPosition = oldXPProximityPosition; |
| 383 xpctxt->contextSize = oldXPContextSize; |
| 384 xpctxt->nsNr = oldXPNsNr; |
| 385 xpctxt->namespaces = oldXPNamespaces; |
| 386 |
| 387 return(res); |
| 388 } |
| 389 |
| 390 /** |
| 391 * xsltPreCompEvalToBoolean: |
| 392 * @ctxt: transform context |
| 393 * @node: context node |
| 394 * @comp: precompiled expression |
| 395 * |
| 396 * Evaluate a precompiled XPath expression as boolean. |
| 397 */ |
| 398 static int |
| 399 xsltPreCompEvalToBoolean(xsltTransformContextPtr ctxt, xmlNodePtr node, |
| 400 xsltStylePreCompPtr comp) { |
| 401 int res; |
| 402 xmlXPathContextPtr xpctxt; |
| 403 xmlNodePtr oldXPContextNode; |
| 404 xmlNsPtr *oldXPNamespaces; |
| 405 int oldXPProximityPosition, oldXPContextSize, oldXPNsNr; |
| 406 |
| 407 xpctxt = ctxt->xpathCtxt; |
| 408 oldXPContextNode = xpctxt->node; |
| 409 oldXPProximityPosition = xpctxt->proximityPosition; |
| 410 oldXPContextSize = xpctxt->contextSize; |
| 411 oldXPNsNr = xpctxt->nsNr; |
| 412 oldXPNamespaces = xpctxt->namespaces; |
| 413 |
| 414 xpctxt->node = node; |
| 415 #ifdef XSLT_REFACTORED |
| 416 if (comp->inScopeNs != NULL) { |
| 417 xpctxt->namespaces = comp->inScopeNs->list; |
| 418 xpctxt->nsNr = comp->inScopeNs->xpathNumber; |
| 419 } else { |
| 420 xpctxt->namespaces = NULL; |
| 421 xpctxt->nsNr = 0; |
| 422 } |
| 423 #else |
| 424 xpctxt->namespaces = comp->nsList; |
| 425 xpctxt->nsNr = comp->nsNr; |
| 426 #endif |
| 427 |
| 428 res = xmlXPathCompiledEvalToBoolean(comp->comp, xpctxt); |
| 429 |
| 430 xpctxt->node = oldXPContextNode; |
| 431 xpctxt->proximityPosition = oldXPProximityPosition; |
| 432 xpctxt->contextSize = oldXPContextSize; |
| 433 xpctxt->nsNr = oldXPNsNr; |
| 434 xpctxt->namespaces = oldXPNamespaces; |
| 435 |
| 436 return(res); |
| 437 } |
| 438 |
341 /************************************************************************ | 439 /************************************************************************ |
342 * * | 440 * * |
343 * XInclude default settings * | 441 * XInclude default settings * |
344 * * | 442 * * |
345 ************************************************************************/ | 443 ************************************************************************/ |
346 | 444 |
347 static int xsltDoXIncludeDefault = 0; | 445 static int xsltDoXIncludeDefault = 0; |
348 | 446 |
349 /** | 447 /** |
350 * xsltSetXIncludeDefault: | 448 * xsltSetXIncludeDefault: |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 /* | 922 /* |
825 * Default processing. | 923 * Default processing. |
826 */ | 924 */ |
827 if ((target != NULL) && (target->last != NULL) && | 925 if ((target != NULL) && (target->last != NULL) && |
828 (target->last->type == XML_TEXT_NODE) && | 926 (target->last->type == XML_TEXT_NODE) && |
829 (target->last->name == xmlStringText)) { | 927 (target->last->name == xmlStringText)) { |
830 return(xsltAddTextString(ctxt, target->last, string, len)); | 928 return(xsltAddTextString(ctxt, target->last, string, len)); |
831 } | 929 } |
832 copy = xmlNewTextLen(string, len); | 930 copy = xmlNewTextLen(string, len); |
833 } | 931 } |
| 932 if (copy != NULL && target != NULL) |
| 933 copy = xsltAddChild(target, copy); |
834 if (copy != NULL) { | 934 if (copy != NULL) { |
835 if (target != NULL) | |
836 copy = xsltAddChild(target, copy); | |
837 ctxt->lasttext = copy->content; | 935 ctxt->lasttext = copy->content; |
838 ctxt->lasttsize = len; | 936 ctxt->lasttsize = len; |
839 ctxt->lasttuse = len; | 937 ctxt->lasttuse = len; |
840 } else { | 938 } else { |
841 xsltTransformError(ctxt, NULL, target, | 939 xsltTransformError(ctxt, NULL, target, |
842 "xsltCopyTextString: text copy failed\n"); | 940 "xsltCopyTextString: text copy failed\n"); |
843 ctxt->lasttext = NULL; | 941 ctxt->lasttext = NULL; |
844 } | 942 } |
845 return(copy); | 943 return(copy); |
846 } | 944 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 if ((node->type == XML_DTD_NODE) || (insert == NULL)) | 1313 if ((node->type == XML_DTD_NODE) || (insert == NULL)) |
1216 return(NULL); | 1314 return(NULL); |
1217 if ((node->type == XML_TEXT_NODE) || | 1315 if ((node->type == XML_TEXT_NODE) || |
1218 (node->type == XML_CDATA_SECTION_NODE)) | 1316 (node->type == XML_CDATA_SECTION_NODE)) |
1219 return(xsltCopyText(ctxt, insert, node, 0)); | 1317 return(xsltCopyText(ctxt, insert, node, 0)); |
1220 | 1318 |
1221 copy = xmlDocCopyNode(node, insert->doc, 0); | 1319 copy = xmlDocCopyNode(node, insert->doc, 0); |
1222 if (copy != NULL) { | 1320 if (copy != NULL) { |
1223 copy->doc = ctxt->output; | 1321 copy->doc = ctxt->output; |
1224 copy = xsltAddChild(insert, copy); | 1322 copy = xsltAddChild(insert, copy); |
| 1323 if (copy == NULL) { |
| 1324 xsltTransformError(ctxt, NULL, node, |
| 1325 "xsltShallowCopyElem: copy failed\n"); |
| 1326 return (copy); |
| 1327 } |
1225 | 1328 |
1226 if (node->type == XML_ELEMENT_NODE) { | 1329 if (node->type == XML_ELEMENT_NODE) { |
1227 /* | 1330 /* |
1228 * Add namespaces as they are needed | 1331 * Add namespaces as they are needed |
1229 */ | 1332 */ |
1230 if (node->nsDef != NULL) { | 1333 if (node->nsDef != NULL) { |
1231 /* | 1334 /* |
1232 * TODO: Remove the LRE case in the refactored code | 1335 * TODO: Remove the LRE case in the refactored code |
1233 * gets enabled. | 1336 * gets enabled. |
1234 */ | 1337 */ |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 copy = xsltCopyTreeList(ctxt, invocNode, | 1651 copy = xsltCopyTreeList(ctxt, invocNode, |
1549 node->children, insert, 0, 0); | 1652 node->children, insert, 0, 0); |
1550 else | 1653 else |
1551 copy = NULL; | 1654 copy = NULL; |
1552 return(copy); | 1655 return(copy); |
1553 } | 1656 } |
1554 copy = xmlDocCopyNode(node, insert->doc, 0); | 1657 copy = xmlDocCopyNode(node, insert->doc, 0); |
1555 if (copy != NULL) { | 1658 if (copy != NULL) { |
1556 copy->doc = ctxt->output; | 1659 copy->doc = ctxt->output; |
1557 copy = xsltAddChild(insert, copy); | 1660 copy = xsltAddChild(insert, copy); |
| 1661 if (copy == NULL) { |
| 1662 xsltTransformError(ctxt, NULL, invocNode, |
| 1663 "xsltCopyTreeInternal: Copying of '%s' failed.\n", node->name); |
| 1664 return (copy); |
| 1665 } |
1558 /* | 1666 /* |
1559 * The node may have been coalesced into another text node. | 1667 * The node may have been coalesced into another text node. |
1560 */ | 1668 */ |
1561 if (insert->last != copy) | 1669 if (insert->last != copy) |
1562 return(insert->last); | 1670 return(insert->last); |
1563 copy->next = NULL; | 1671 copy->next = NULL; |
1564 | 1672 |
1565 if (node->type == XML_ELEMENT_NODE) { | 1673 if (node->type == XML_ELEMENT_NODE) { |
1566 /* | 1674 /* |
1567 * Copy in-scope namespace nodes. | 1675 * Copy in-scope namespace nodes. |
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 #endif | 3707 #endif |
3600 } | 3708 } |
3601 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic); | 3709 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic); |
3602 } | 3710 } |
3603 if (res == NULL) | 3711 if (res == NULL) |
3604 goto error; | 3712 goto error; |
3605 res->dict = ctxt->dict; | 3713 res->dict = ctxt->dict; |
3606 xmlDictReference(res->dict); | 3714 xmlDictReference(res->dict); |
3607 } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { | 3715 } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { |
3608 xsltTransformError(ctxt, NULL, inst, | 3716 xsltTransformError(ctxt, NULL, inst, |
3609 » "xsltDocumentElem: unsupported method xhtml\n", | 3717 » "xsltDocumentElem: unsupported method xhtml\n"); |
3610 » » style->method); | |
3611 ctxt->type = XSLT_OUTPUT_HTML; | 3718 ctxt->type = XSLT_OUTPUT_HTML; |
3612 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic); | 3719 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic); |
3613 if (res == NULL) | 3720 if (res == NULL) |
3614 goto error; | 3721 goto error; |
3615 res->dict = ctxt->dict; | 3722 res->dict = ctxt->dict; |
3616 xmlDictReference(res->dict); | 3723 xmlDictReference(res->dict); |
3617 } else if (xmlStrEqual(method, (const xmlChar *) "text")) { | 3724 } else if (xmlStrEqual(method, (const xmlChar *) "text")) { |
3618 ctxt->type = XSLT_OUTPUT_TEXT; | 3725 ctxt->type = XSLT_OUTPUT_TEXT; |
3619 res = xmlNewDoc(style->version); | 3726 res = xmlNewDoc(style->version); |
3620 if (res == NULL) | 3727 if (res == NULL) |
3621 goto error; | 3728 goto error; |
3622 res->dict = ctxt->dict; | 3729 res->dict = ctxt->dict; |
3623 xmlDictReference(res->dict); | 3730 xmlDictReference(res->dict); |
3624 #ifdef WITH_XSLT_DEBUG | 3731 #ifdef WITH_XSLT_DEBUG |
3625 xsltGenericDebug(xsltGenericDebugContext, | 3732 xsltGenericDebug(xsltGenericDebugContext, |
3626 "reusing transformation dict for output\n"); | 3733 "reusing transformation dict for output\n"); |
3627 #endif | 3734 #endif |
3628 } else { | 3735 } else { |
3629 xsltTransformError(ctxt, NULL, inst, | 3736 xsltTransformError(ctxt, NULL, inst, |
3630 » » » "xsltDocumentElem: unsupported method %s\n", | 3737 » » » "xsltDocumentElem: unsupported method (%s)\n", |
3631 » » style->method); | 3738 » » method); |
3632 goto error; | 3739 goto error; |
3633 } | 3740 } |
3634 } else { | 3741 } else { |
3635 ctxt->type = XSLT_OUTPUT_XML; | 3742 ctxt->type = XSLT_OUTPUT_XML; |
3636 res = xmlNewDoc(style->version); | 3743 res = xmlNewDoc(style->version); |
3637 if (res == NULL) | 3744 if (res == NULL) |
3638 goto error; | 3745 goto error; |
3639 res->dict = ctxt->dict; | 3746 res->dict = ctxt->dict; |
3640 xmlDictReference(res->dict); | 3747 xmlDictReference(res->dict); |
3641 #ifdef WITH_XSLT_DEBUG | 3748 #ifdef WITH_XSLT_DEBUG |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4027 copy = xmlNewDocNodeEatName(ctxt->output, NULL, (xmlChar *)name, NULL); | 4134 copy = xmlNewDocNodeEatName(ctxt->output, NULL, (xmlChar *)name, NULL); |
4028 } else { | 4135 } else { |
4029 copy = xmlNewDocNode(ctxt->output, NULL, (xmlChar *)name, NULL); | 4136 copy = xmlNewDocNode(ctxt->output, NULL, (xmlChar *)name, NULL); |
4030 } | 4137 } |
4031 if (copy == NULL) { | 4138 if (copy == NULL) { |
4032 xsltTransformError(ctxt, NULL, inst, | 4139 xsltTransformError(ctxt, NULL, inst, |
4033 "xsl:element : creation of %s failed\n", name); | 4140 "xsl:element : creation of %s failed\n", name); |
4034 return; | 4141 return; |
4035 } | 4142 } |
4036 copy = xsltAddChild(ctxt->insert, copy); | 4143 copy = xsltAddChild(ctxt->insert, copy); |
| 4144 if (copy == NULL) { |
| 4145 xsltTransformError(ctxt, NULL, inst, |
| 4146 "xsl:element : xsltAddChild failed\n"); |
| 4147 return; |
| 4148 } |
4037 | 4149 |
4038 /* | 4150 /* |
4039 * Namespace | 4151 * Namespace |
4040 * --------- | 4152 * --------- |
4041 */ | 4153 */ |
4042 if (comp->has_ns) { | 4154 if (comp->has_ns) { |
4043 if (comp->ns != NULL) { | 4155 if (comp->ns != NULL) { |
4044 /* | 4156 /* |
4045 * No AVT; just plain text for the namespace name. | 4157 * No AVT; just plain text for the namespace name. |
4046 */ | 4158 */ |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4280 xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node, | 4392 xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node, |
4281 xmlNodePtr inst, xsltStylePreCompPtr castedComp) { | 4393 xmlNodePtr inst, xsltStylePreCompPtr castedComp) { |
4282 #ifdef XSLT_REFACTORED | 4394 #ifdef XSLT_REFACTORED |
4283 xsltStyleItemCopyOfPtr comp = (xsltStyleItemCopyOfPtr) castedComp; | 4395 xsltStyleItemCopyOfPtr comp = (xsltStyleItemCopyOfPtr) castedComp; |
4284 #else | 4396 #else |
4285 xsltStylePreCompPtr comp = castedComp; | 4397 xsltStylePreCompPtr comp = castedComp; |
4286 #endif | 4398 #endif |
4287 xmlXPathObjectPtr res = NULL; | 4399 xmlXPathObjectPtr res = NULL; |
4288 xmlNodeSetPtr list = NULL; | 4400 xmlNodeSetPtr list = NULL; |
4289 int i; | 4401 int i; |
4290 xmlDocPtr oldXPContextDoc; | |
4291 xmlNsPtr *oldXPNamespaces; | |
4292 xmlNodePtr oldXPContextNode; | |
4293 int oldXPProximityPosition, oldXPContextSize, oldXPNsNr; | |
4294 xmlXPathContextPtr xpctxt; | |
4295 | 4402 |
4296 if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) | 4403 if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) |
4297 return; | 4404 return; |
4298 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) { | 4405 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) { |
4299 xsltTransformError(ctxt, NULL, inst, | 4406 xsltTransformError(ctxt, NULL, inst, |
4300 "xsl:copy-of : compilation failed\n"); | 4407 "xsl:copy-of : compilation failed\n"); |
4301 return; | 4408 return; |
4302 } | 4409 } |
4303 | 4410 |
4304 /* | 4411 /* |
(...skipping 15 matching lines...) Expand all Loading... |
4320 */ | 4427 */ |
4321 | 4428 |
4322 #ifdef WITH_XSLT_DEBUG_PROCESS | 4429 #ifdef WITH_XSLT_DEBUG_PROCESS |
4323 XSLT_TRACE(ctxt,XSLT_TRACE_COPY_OF,xsltGenericDebug(xsltGenericDebugContext, | 4430 XSLT_TRACE(ctxt,XSLT_TRACE_COPY_OF,xsltGenericDebug(xsltGenericDebugContext, |
4324 "xsltCopyOf: select %s\n", comp->select)); | 4431 "xsltCopyOf: select %s\n", comp->select)); |
4325 #endif | 4432 #endif |
4326 | 4433 |
4327 /* | 4434 /* |
4328 * Evaluate the "select" expression. | 4435 * Evaluate the "select" expression. |
4329 */ | 4436 */ |
4330 xpctxt = ctxt->xpathCtxt; | 4437 res = xsltPreCompEval(ctxt, node, comp); |
4331 oldXPContextDoc = xpctxt->doc; | |
4332 oldXPContextNode = xpctxt->node; | |
4333 oldXPProximityPosition = xpctxt->proximityPosition; | |
4334 oldXPContextSize = xpctxt->contextSize; | |
4335 oldXPNsNr = xpctxt->nsNr; | |
4336 oldXPNamespaces = xpctxt->namespaces; | |
4337 | |
4338 xpctxt->node = node; | |
4339 if (comp != NULL) { | |
4340 | |
4341 #ifdef XSLT_REFACTORED | |
4342 » if (comp->inScopeNs != NULL) { | |
4343 » xpctxt->namespaces = comp->inScopeNs->list; | |
4344 » xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
4345 » } else { | |
4346 » xpctxt->namespaces = NULL; | |
4347 » xpctxt->nsNr = 0; | |
4348 » } | |
4349 #else | |
4350 » xpctxt->namespaces = comp->nsList; | |
4351 » xpctxt->nsNr = comp->nsNr; | |
4352 #endif | |
4353 } else { | |
4354 » xpctxt->namespaces = NULL; | |
4355 » xpctxt->nsNr = 0; | |
4356 } | |
4357 | |
4358 res = xmlXPathCompiledEval(comp->comp, xpctxt); | |
4359 | |
4360 xpctxt->doc = oldXPContextDoc; | |
4361 xpctxt->node = oldXPContextNode; | |
4362 xpctxt->contextSize = oldXPContextSize; | |
4363 xpctxt->proximityPosition = oldXPProximityPosition; | |
4364 xpctxt->nsNr = oldXPNsNr; | |
4365 xpctxt->namespaces = oldXPNamespaces; | |
4366 | 4438 |
4367 if (res != NULL) { | 4439 if (res != NULL) { |
4368 if (res->type == XPATH_NODESET) { | 4440 if (res->type == XPATH_NODESET) { |
4369 /* | 4441 /* |
4370 * Node-set | 4442 * Node-set |
4371 * -------- | 4443 * -------- |
4372 */ | 4444 */ |
4373 #ifdef WITH_XSLT_DEBUG_PROCESS | 4445 #ifdef WITH_XSLT_DEBUG_PROCESS |
4374 XSLT_TRACE(ctxt,XSLT_TRACE_COPY_OF,xsltGenericDebug(xsltGenericDebug
Context, | 4446 XSLT_TRACE(ctxt,XSLT_TRACE_COPY_OF,xsltGenericDebug(xsltGenericDebug
Context, |
4375 "xsltCopyOf: result is a node set\n")); | 4447 "xsltCopyOf: result is a node set\n")); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4465 xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, | 4537 xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, |
4466 xmlNodePtr inst, xsltStylePreCompPtr castedComp) | 4538 xmlNodePtr inst, xsltStylePreCompPtr castedComp) |
4467 { | 4539 { |
4468 #ifdef XSLT_REFACTORED | 4540 #ifdef XSLT_REFACTORED |
4469 xsltStyleItemValueOfPtr comp = (xsltStyleItemValueOfPtr) castedComp; | 4541 xsltStyleItemValueOfPtr comp = (xsltStyleItemValueOfPtr) castedComp; |
4470 #else | 4542 #else |
4471 xsltStylePreCompPtr comp = castedComp; | 4543 xsltStylePreCompPtr comp = castedComp; |
4472 #endif | 4544 #endif |
4473 xmlXPathObjectPtr res = NULL; | 4545 xmlXPathObjectPtr res = NULL; |
4474 xmlChar *value = NULL; | 4546 xmlChar *value = NULL; |
4475 xmlDocPtr oldXPContextDoc; | |
4476 xmlNsPtr *oldXPNamespaces; | |
4477 xmlNodePtr oldXPContextNode; | |
4478 int oldXPProximityPosition, oldXPContextSize, oldXPNsNr; | |
4479 xmlXPathContextPtr xpctxt; | |
4480 | 4547 |
4481 if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) | 4548 if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) |
4482 return; | 4549 return; |
4483 | 4550 |
4484 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) { | 4551 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) { |
4485 xsltTransformError(ctxt, NULL, inst, | 4552 xsltTransformError(ctxt, NULL, inst, |
4486 "Internal error in xsltValueOf(): " | 4553 "Internal error in xsltValueOf(): " |
4487 "The XSLT 'value-of' instruction was not compiled.\n"); | 4554 "The XSLT 'value-of' instruction was not compiled.\n"); |
4488 return; | 4555 return; |
4489 } | 4556 } |
4490 | 4557 |
4491 #ifdef WITH_XSLT_DEBUG_PROCESS | 4558 #ifdef WITH_XSLT_DEBUG_PROCESS |
4492 XSLT_TRACE(ctxt,XSLT_TRACE_VALUE_OF,xsltGenericDebug(xsltGenericDebugContext
, | 4559 XSLT_TRACE(ctxt,XSLT_TRACE_VALUE_OF,xsltGenericDebug(xsltGenericDebugContext
, |
4493 "xsltValueOf: select %s\n", comp->select)); | 4560 "xsltValueOf: select %s\n", comp->select)); |
4494 #endif | 4561 #endif |
4495 | 4562 |
4496 xpctxt = ctxt->xpathCtxt; | 4563 res = xsltPreCompEval(ctxt, node, comp); |
4497 oldXPContextDoc = xpctxt->doc; | |
4498 oldXPContextNode = xpctxt->node; | |
4499 oldXPProximityPosition = xpctxt->proximityPosition; | |
4500 oldXPContextSize = xpctxt->contextSize; | |
4501 oldXPNsNr = xpctxt->nsNr; | |
4502 oldXPNamespaces = xpctxt->namespaces; | |
4503 | |
4504 xpctxt->node = node; | |
4505 if (comp != NULL) { | |
4506 | |
4507 #ifdef XSLT_REFACTORED | |
4508 » if (comp->inScopeNs != NULL) { | |
4509 » xpctxt->namespaces = comp->inScopeNs->list; | |
4510 » xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
4511 » } else { | |
4512 » xpctxt->namespaces = NULL; | |
4513 » xpctxt->nsNr = 0; | |
4514 » } | |
4515 #else | |
4516 » xpctxt->namespaces = comp->nsList; | |
4517 » xpctxt->nsNr = comp->nsNr; | |
4518 #endif | |
4519 } else { | |
4520 » xpctxt->namespaces = NULL; | |
4521 » xpctxt->nsNr = 0; | |
4522 } | |
4523 | |
4524 res = xmlXPathCompiledEval(comp->comp, xpctxt); | |
4525 | |
4526 xpctxt->doc = oldXPContextDoc; | |
4527 xpctxt->node = oldXPContextNode; | |
4528 xpctxt->contextSize = oldXPContextSize; | |
4529 xpctxt->proximityPosition = oldXPProximityPosition; | |
4530 xpctxt->nsNr = oldXPNsNr; | |
4531 xpctxt->namespaces = oldXPNamespaces; | |
4532 | 4564 |
4533 /* | 4565 /* |
4534 * Cast the XPath object to string. | 4566 * Cast the XPath object to string. |
4535 */ | 4567 */ |
4536 if (res != NULL) { | 4568 if (res != NULL) { |
4537 value = xmlXPathCastToString(res); | 4569 value = xmlXPathCastToString(res); |
4538 if (value == NULL) { | 4570 if (value == NULL) { |
4539 xsltTransformError(ctxt, NULL, inst, | 4571 xsltTransformError(ctxt, NULL, inst, |
4540 "Internal error in xsltValueOf(): " | 4572 "Internal error in xsltValueOf(): " |
4541 "failed to cast an XPath object to string.\n"); | 4573 "failed to cast an XPath object to string.\n"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4577 */ | 4609 */ |
4578 void | 4610 void |
4579 xsltNumber(xsltTransformContextPtr ctxt, xmlNodePtr node, | 4611 xsltNumber(xsltTransformContextPtr ctxt, xmlNodePtr node, |
4580 xmlNodePtr inst, xsltStylePreCompPtr castedComp) | 4612 xmlNodePtr inst, xsltStylePreCompPtr castedComp) |
4581 { | 4613 { |
4582 #ifdef XSLT_REFACTORED | 4614 #ifdef XSLT_REFACTORED |
4583 xsltStyleItemNumberPtr comp = (xsltStyleItemNumberPtr) castedComp; | 4615 xsltStyleItemNumberPtr comp = (xsltStyleItemNumberPtr) castedComp; |
4584 #else | 4616 #else |
4585 xsltStylePreCompPtr comp = castedComp; | 4617 xsltStylePreCompPtr comp = castedComp; |
4586 #endif | 4618 #endif |
| 4619 xmlXPathContextPtr xpctxt; |
| 4620 xmlNsPtr *oldXPNamespaces; |
| 4621 int oldXPNsNr; |
| 4622 |
4587 if (comp == NULL) { | 4623 if (comp == NULL) { |
4588 xsltTransformError(ctxt, NULL, inst, | 4624 xsltTransformError(ctxt, NULL, inst, |
4589 "xsl:number : compilation failed\n"); | 4625 "xsl:number : compilation failed\n"); |
4590 return; | 4626 return; |
4591 } | 4627 } |
4592 | 4628 |
4593 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) | 4629 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) |
4594 return; | 4630 return; |
4595 | 4631 |
4596 comp->numdata.doc = inst->doc; | 4632 comp->numdata.doc = inst->doc; |
4597 comp->numdata.node = inst; | 4633 comp->numdata.node = inst; |
4598 | 4634 |
| 4635 xpctxt = ctxt->xpathCtxt; |
| 4636 oldXPNsNr = xpctxt->nsNr; |
| 4637 oldXPNamespaces = xpctxt->namespaces; |
| 4638 |
| 4639 #ifdef XSLT_REFACTORED |
| 4640 if (comp->inScopeNs != NULL) { |
| 4641 xpctxt->namespaces = comp->inScopeNs->list; |
| 4642 xpctxt->nsNr = comp->inScopeNs->xpathNumber; |
| 4643 } else { |
| 4644 xpctxt->namespaces = NULL; |
| 4645 xpctxt->nsNr = 0; |
| 4646 } |
| 4647 #else |
| 4648 xpctxt->namespaces = comp->nsList; |
| 4649 xpctxt->nsNr = comp->nsNr; |
| 4650 #endif |
| 4651 |
4599 xsltNumberFormat(ctxt, &comp->numdata, node); | 4652 xsltNumberFormat(ctxt, &comp->numdata, node); |
| 4653 |
| 4654 xpctxt->nsNr = oldXPNsNr; |
| 4655 xpctxt->namespaces = oldXPNamespaces; |
4600 } | 4656 } |
4601 | 4657 |
4602 /** | 4658 /** |
4603 * xsltApplyImports: | 4659 * xsltApplyImports: |
4604 * @ctxt: an XSLT transformation context | 4660 * @ctxt: an XSLT transformation context |
4605 * @contextNode: the current node in the source tree. | 4661 * @contextNode: the current node in the source tree. |
4606 * @inst: the element node of the XSLT 'apply-imports' instruction | 4662 * @inst: the element node of the XSLT 'apply-imports' instruction |
4607 * @comp: the compiled instruction | 4663 * @comp: the compiled instruction |
4608 * | 4664 * |
4609 * Process the XSLT apply-imports element. | 4665 * Process the XSLT apply-imports element. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4783 #ifdef XSLT_REFACTORED | 4839 #ifdef XSLT_REFACTORED |
4784 xsltStyleItemApplyTemplatesPtr comp = | 4840 xsltStyleItemApplyTemplatesPtr comp = |
4785 (xsltStyleItemApplyTemplatesPtr) castedComp; | 4841 (xsltStyleItemApplyTemplatesPtr) castedComp; |
4786 #else | 4842 #else |
4787 xsltStylePreCompPtr comp = castedComp; | 4843 xsltStylePreCompPtr comp = castedComp; |
4788 #endif | 4844 #endif |
4789 int i; | 4845 int i; |
4790 xmlNodePtr cur, delNode = NULL, oldContextNode; | 4846 xmlNodePtr cur, delNode = NULL, oldContextNode; |
4791 xmlNodeSetPtr list = NULL, oldList; | 4847 xmlNodeSetPtr list = NULL, oldList; |
4792 xsltStackElemPtr withParams = NULL; | 4848 xsltStackElemPtr withParams = NULL; |
4793 int oldXPProximityPosition, oldXPContextSize, oldXPNsNr; | 4849 int oldXPProximityPosition, oldXPContextSize; |
4794 const xmlChar *oldMode, *oldModeURI; | 4850 const xmlChar *oldMode, *oldModeURI; |
4795 xmlDocPtr oldXPDoc; | 4851 xmlDocPtr oldXPDoc; |
4796 xsltDocumentPtr oldDocInfo; | 4852 xsltDocumentPtr oldDocInfo; |
4797 xmlXPathContextPtr xpctxt; | 4853 xmlXPathContextPtr xpctxt; |
4798 xmlNsPtr *oldXPNamespaces; | |
4799 | 4854 |
4800 if (comp == NULL) { | 4855 if (comp == NULL) { |
4801 xsltTransformError(ctxt, NULL, inst, | 4856 xsltTransformError(ctxt, NULL, inst, |
4802 "xsl:apply-templates : compilation failed\n"); | 4857 "xsl:apply-templates : compilation failed\n"); |
4803 return; | 4858 return; |
4804 } | 4859 } |
4805 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) | 4860 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) |
4806 return; | 4861 return; |
4807 | 4862 |
4808 #ifdef WITH_XSLT_DEBUG_PROCESS | 4863 #ifdef WITH_XSLT_DEBUG_PROCESS |
(...skipping 13 matching lines...) Expand all Loading... |
4822 oldList = ctxt->nodeList; | 4877 oldList = ctxt->nodeList; |
4823 | 4878 |
4824 /* | 4879 /* |
4825 * The xpath context size and proximity position, as | 4880 * The xpath context size and proximity position, as |
4826 * well as the xpath and context documents, may be changed | 4881 * well as the xpath and context documents, may be changed |
4827 * so we save their initial state and will restore on exit | 4882 * so we save their initial state and will restore on exit |
4828 */ | 4883 */ |
4829 oldXPContextSize = xpctxt->contextSize; | 4884 oldXPContextSize = xpctxt->contextSize; |
4830 oldXPProximityPosition = xpctxt->proximityPosition; | 4885 oldXPProximityPosition = xpctxt->proximityPosition; |
4831 oldXPDoc = xpctxt->doc; | 4886 oldXPDoc = xpctxt->doc; |
4832 oldXPNsNr = xpctxt->nsNr; | |
4833 oldXPNamespaces = xpctxt->namespaces; | |
4834 | 4887 |
4835 /* | 4888 /* |
4836 * Set up contexts. | 4889 * Set up contexts. |
4837 */ | 4890 */ |
4838 ctxt->mode = comp->mode; | 4891 ctxt->mode = comp->mode; |
4839 ctxt->modeURI = comp->modeURI; | 4892 ctxt->modeURI = comp->modeURI; |
4840 | 4893 |
4841 if (comp->select != NULL) { | 4894 if (comp->select != NULL) { |
4842 xmlXPathObjectPtr res = NULL; | 4895 xmlXPathObjectPtr res = NULL; |
4843 | 4896 |
4844 if (comp->comp == NULL) { | 4897 if (comp->comp == NULL) { |
4845 xsltTransformError(ctxt, NULL, inst, | 4898 xsltTransformError(ctxt, NULL, inst, |
4846 "xsl:apply-templates : compilation failed\n"); | 4899 "xsl:apply-templates : compilation failed\n"); |
4847 goto error; | 4900 goto error; |
4848 } | 4901 } |
4849 #ifdef WITH_XSLT_DEBUG_PROCESS | 4902 #ifdef WITH_XSLT_DEBUG_PROCESS |
4850 XSLT_TRACE(ctxt,XSLT_TRACE_APPLY_TEMPLATES,xsltGenericDebug(xsltGenericD
ebugContext, | 4903 XSLT_TRACE(ctxt,XSLT_TRACE_APPLY_TEMPLATES,xsltGenericDebug(xsltGenericD
ebugContext, |
4851 "xsltApplyTemplates: select %s\n", comp->select)); | 4904 "xsltApplyTemplates: select %s\n", comp->select)); |
4852 #endif | 4905 #endif |
4853 | 4906 |
4854 » /* | 4907 » res = xsltPreCompEval(ctxt, node, comp); |
4855 » * Set up XPath. | |
4856 » */ | |
4857 » xpctxt->node = node; /* Set the "context node" */ | |
4858 #ifdef XSLT_REFACTORED | |
4859 » if (comp->inScopeNs != NULL) { | |
4860 » xpctxt->namespaces = comp->inScopeNs->list; | |
4861 » xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
4862 » } else { | |
4863 » xpctxt->namespaces = NULL; | |
4864 » xpctxt->nsNr = 0; | |
4865 » } | |
4866 #else | |
4867 » xpctxt->namespaces = comp->nsList; | |
4868 » xpctxt->nsNr = comp->nsNr; | |
4869 #endif | |
4870 » res = xmlXPathCompiledEval(comp->comp, xpctxt); | |
4871 | 4908 |
4872 xpctxt->contextSize = oldXPContextSize; | |
4873 xpctxt->proximityPosition = oldXPProximityPosition; | |
4874 if (res != NULL) { | 4909 if (res != NULL) { |
4875 if (res->type == XPATH_NODESET) { | 4910 if (res->type == XPATH_NODESET) { |
4876 list = res->nodesetval; /* consume the node set */ | 4911 list = res->nodesetval; /* consume the node set */ |
4877 res->nodesetval = NULL; | 4912 res->nodesetval = NULL; |
4878 } else { | 4913 } else { |
4879 xsltTransformError(ctxt, NULL, inst, | 4914 xsltTransformError(ctxt, NULL, inst, |
4880 "The 'select' expression did not evaluate to a " | 4915 "The 'select' expression did not evaluate to a " |
4881 "node set.\n"); | 4916 "node set.\n"); |
4882 ctxt->state = XSLT_STATE_STOPPED; | 4917 ctxt->state = XSLT_STATE_STOPPED; |
4883 xmlXPathFreeObject(res); | 4918 xmlXPathFreeObject(res); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5146 /* | 5181 /* |
5147 * Free the parameter list. | 5182 * Free the parameter list. |
5148 */ | 5183 */ |
5149 if (withParams != NULL) | 5184 if (withParams != NULL) |
5150 xsltFreeStackElemList(withParams); | 5185 xsltFreeStackElemList(withParams); |
5151 if (list != NULL) | 5186 if (list != NULL) |
5152 xmlXPathFreeNodeSet(list); | 5187 xmlXPathFreeNodeSet(list); |
5153 /* | 5188 /* |
5154 * Restore context states. | 5189 * Restore context states. |
5155 */ | 5190 */ |
5156 xpctxt->nsNr = oldXPNsNr; | |
5157 xpctxt->namespaces = oldXPNamespaces; | |
5158 xpctxt->doc = oldXPDoc; | 5191 xpctxt->doc = oldXPDoc; |
5159 xpctxt->contextSize = oldXPContextSize; | 5192 xpctxt->contextSize = oldXPContextSize; |
5160 xpctxt->proximityPosition = oldXPProximityPosition; | 5193 xpctxt->proximityPosition = oldXPProximityPosition; |
5161 | 5194 |
5162 ctxt->document = oldDocInfo; | 5195 ctxt->document = oldDocInfo; |
5163 ctxt->nodeList = oldList; | 5196 ctxt->nodeList = oldList; |
5164 ctxt->node = oldContextNode; | 5197 ctxt->node = oldContextNode; |
5165 ctxt->mode = oldMode; | 5198 ctxt->mode = oldMode; |
5166 ctxt->modeURI = oldModeURI; | 5199 ctxt->modeURI = oldModeURI; |
5167 } | 5200 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5203 #else | 5236 #else |
5204 if ((! IS_XSLT_ELEM(cur)) || (! IS_XSLT_NAME(cur, "when"))) { | 5237 if ((! IS_XSLT_ELEM(cur)) || (! IS_XSLT_NAME(cur, "when"))) { |
5205 xsltTransformError(ctxt, NULL, inst, | 5238 xsltTransformError(ctxt, NULL, inst, |
5206 "xsl:choose: xsl:when expected first\n"); | 5239 "xsl:choose: xsl:when expected first\n"); |
5207 return; | 5240 return; |
5208 } | 5241 } |
5209 #endif | 5242 #endif |
5210 | 5243 |
5211 { | 5244 { |
5212 int testRes = 0, res = 0; | 5245 int testRes = 0, res = 0; |
5213 xmlXPathContextPtr xpctxt = ctxt->xpathCtxt; | |
5214 xmlDocPtr oldXPContextDoc = xpctxt->doc; | |
5215 int oldXPProximityPosition = xpctxt->proximityPosition; | |
5216 int oldXPContextSize = xpctxt->contextSize; | |
5217 xmlNsPtr *oldXPNamespaces = xpctxt->namespaces; | |
5218 int oldXPNsNr = xpctxt->nsNr; | |
5219 | 5246 |
5220 #ifdef XSLT_REFACTORED | 5247 #ifdef XSLT_REFACTORED |
5221 xsltStyleItemWhenPtr wcomp = NULL; | 5248 xsltStyleItemWhenPtr wcomp = NULL; |
5222 #else | 5249 #else |
5223 xsltStylePreCompPtr wcomp = NULL; | 5250 xsltStylePreCompPtr wcomp = NULL; |
5224 #endif | 5251 #endif |
5225 | 5252 |
5226 /* | 5253 /* |
5227 * Process xsl:when --------------------------------------------------- | 5254 * Process xsl:when --------------------------------------------------- |
5228 */ | 5255 */ |
(...skipping 16 matching lines...) Expand all Loading... |
5245 * TODO: Isn't comp->templ always NULL for xsl:choose? | 5272 * TODO: Isn't comp->templ always NULL for xsl:choose? |
5246 */ | 5273 */ |
5247 xslHandleDebugger(cur, contextNode, NULL, ctxt); | 5274 xslHandleDebugger(cur, contextNode, NULL, ctxt); |
5248 } | 5275 } |
5249 #endif | 5276 #endif |
5250 #ifdef WITH_XSLT_DEBUG_PROCESS | 5277 #ifdef WITH_XSLT_DEBUG_PROCESS |
5251 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugC
ontext, | 5278 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugC
ontext, |
5252 "xsltChoose: test %s\n", wcomp->test)); | 5279 "xsltChoose: test %s\n", wcomp->test)); |
5253 #endif | 5280 #endif |
5254 | 5281 |
5255 xpctxt->node = contextNode; | |
5256 xpctxt->doc = oldXPContextDoc; | |
5257 xpctxt->proximityPosition = oldXPProximityPosition; | |
5258 xpctxt->contextSize = oldXPContextSize; | |
5259 | |
5260 #ifdef XSLT_REFACTORED | |
5261 if (wcomp->inScopeNs != NULL) { | |
5262 xpctxt->namespaces = wcomp->inScopeNs->list; | |
5263 xpctxt->nsNr = wcomp->inScopeNs->xpathNumber; | |
5264 } else { | |
5265 xpctxt->namespaces = NULL; | |
5266 xpctxt->nsNr = 0; | |
5267 } | |
5268 #else | |
5269 xpctxt->namespaces = wcomp->nsList; | |
5270 xpctxt->nsNr = wcomp->nsNr; | |
5271 #endif | |
5272 | |
5273 | |
5274 #ifdef XSLT_FAST_IF | 5282 #ifdef XSLT_FAST_IF |
5275 » res = xmlXPathCompiledEvalToBoolean(wcomp->comp, xpctxt); | 5283 » res = xsltPreCompEvalToBoolean(ctxt, contextNode, wcomp); |
5276 | 5284 |
5277 if (res == -1) { | 5285 if (res == -1) { |
5278 ctxt->state = XSLT_STATE_STOPPED; | 5286 ctxt->state = XSLT_STATE_STOPPED; |
5279 goto error; | 5287 goto error; |
5280 } | 5288 } |
5281 testRes = (res == 1) ? 1 : 0; | 5289 testRes = (res == 1) ? 1 : 0; |
5282 | 5290 |
5283 #else /* XSLT_FAST_IF */ | 5291 #else /* XSLT_FAST_IF */ |
5284 | 5292 |
5285 » res = xmlXPathCompiledEval(wcomp->comp, xpctxt); | 5293 » res = xsltPreCompEval(ctxt, cotextNode, wcomp); |
5286 | 5294 |
5287 if (res != NULL) { | 5295 if (res != NULL) { |
5288 if (res->type != XPATH_BOOLEAN) | 5296 if (res->type != XPATH_BOOLEAN) |
5289 res = xmlXPathConvertBoolean(res); | 5297 res = xmlXPathConvertBoolean(res); |
5290 if (res->type == XPATH_BOOLEAN) | 5298 if (res->type == XPATH_BOOLEAN) |
5291 testRes = res->boolval; | 5299 testRes = res->boolval; |
5292 else { | 5300 else { |
5293 #ifdef WITH_XSLT_DEBUG_PROCESS | 5301 #ifdef WITH_XSLT_DEBUG_PROCESS |
5294 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGener
icDebugContext, | 5302 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGener
icDebugContext, |
5295 "xsltChoose: test didn't evaluate to a boolean\n")); | 5303 "xsltChoose: test didn't evaluate to a boolean\n")); |
(...skipping 28 matching lines...) Expand all Loading... |
5324 if (xslDebugStatus != XSLT_DEBUG_NONE) | 5332 if (xslDebugStatus != XSLT_DEBUG_NONE) |
5325 xslHandleDebugger(cur, contextNode, NULL, ctxt); | 5333 xslHandleDebugger(cur, contextNode, NULL, ctxt); |
5326 #endif | 5334 #endif |
5327 | 5335 |
5328 #ifdef WITH_XSLT_DEBUG_PROCESS | 5336 #ifdef WITH_XSLT_DEBUG_PROCESS |
5329 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugC
ontext, | 5337 XSLT_TRACE(ctxt,XSLT_TRACE_CHOOSE,xsltGenericDebug(xsltGenericDebugC
ontext, |
5330 "evaluating xsl:otherwise\n")); | 5338 "evaluating xsl:otherwise\n")); |
5331 #endif | 5339 #endif |
5332 goto test_is_true; | 5340 goto test_is_true; |
5333 } | 5341 } |
5334 xpctxt->node = contextNode; | |
5335 xpctxt->doc = oldXPContextDoc; | |
5336 xpctxt->proximityPosition = oldXPProximityPosition; | |
5337 xpctxt->contextSize = oldXPContextSize; | |
5338 xpctxt->namespaces = oldXPNamespaces; | |
5339 xpctxt->nsNr = oldXPNsNr; | |
5340 goto exit; | 5342 goto exit; |
5341 | 5343 |
5342 test_is_true: | 5344 test_is_true: |
5343 | 5345 |
5344 xpctxt->node = contextNode; | |
5345 xpctxt->doc = oldXPContextDoc; | |
5346 xpctxt->proximityPosition = oldXPProximityPosition; | |
5347 xpctxt->contextSize = oldXPContextSize; | |
5348 xpctxt->namespaces = oldXPNamespaces; | |
5349 xpctxt->nsNr = oldXPNsNr; | |
5350 goto process_sequence; | 5346 goto process_sequence; |
5351 } | 5347 } |
5352 | 5348 |
5353 process_sequence: | 5349 process_sequence: |
5354 | 5350 |
5355 /* | 5351 /* |
5356 * Instantiate the sequence constructor. | 5352 * Instantiate the sequence constructor. |
5357 */ | 5353 */ |
5358 xsltApplySequenceConstructor(ctxt, ctxt->node, cur->children, | 5354 xsltApplySequenceConstructor(ctxt, ctxt->node, cur->children, |
5359 NULL); | 5355 NULL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5393 return; | 5389 return; |
5394 } | 5390 } |
5395 | 5391 |
5396 #ifdef WITH_XSLT_DEBUG_PROCESS | 5392 #ifdef WITH_XSLT_DEBUG_PROCESS |
5397 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugContext, | 5393 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugContext, |
5398 "xsltIf: test %s\n", comp->test)); | 5394 "xsltIf: test %s\n", comp->test)); |
5399 #endif | 5395 #endif |
5400 | 5396 |
5401 #ifdef XSLT_FAST_IF | 5397 #ifdef XSLT_FAST_IF |
5402 { | 5398 { |
5403 xmlXPathContextPtr xpctxt = ctxt->xpathCtxt; | |
5404 xmlDocPtr oldXPContextDoc = xpctxt->doc; | |
5405 xmlNsPtr *oldXPNamespaces = xpctxt->namespaces; | |
5406 xmlNodePtr oldXPContextNode = xpctxt->node; | |
5407 int oldXPProximityPosition = xpctxt->proximityPosition; | |
5408 int oldXPContextSize = xpctxt->contextSize; | |
5409 int oldXPNsNr = xpctxt->nsNr; | |
5410 xmlDocPtr oldLocalFragmentTop = ctxt->localRVT; | 5399 xmlDocPtr oldLocalFragmentTop = ctxt->localRVT; |
5411 | 5400 |
5412 » xpctxt->node = contextNode; | 5401 » res = xsltPreCompEvalToBoolean(ctxt, contextNode, comp); |
5413 » if (comp != NULL) { | |
5414 | |
5415 #ifdef XSLT_REFACTORED | |
5416 » if (comp->inScopeNs != NULL) { | |
5417 » » xpctxt->namespaces = comp->inScopeNs->list; | |
5418 » » xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
5419 » } else { | |
5420 » » xpctxt->namespaces = NULL; | |
5421 » » xpctxt->nsNr = 0; | |
5422 » } | |
5423 #else | |
5424 » xpctxt->namespaces = comp->nsList; | |
5425 » xpctxt->nsNr = comp->nsNr; | |
5426 #endif | |
5427 » } else { | |
5428 » xpctxt->namespaces = NULL; | |
5429 » xpctxt->nsNr = 0; | |
5430 » } | |
5431 » /* | |
5432 » * This XPath function is optimized for boolean results. | |
5433 » */ | |
5434 » res = xmlXPathCompiledEvalToBoolean(comp->comp, xpctxt); | |
5435 | 5402 |
5436 /* | 5403 /* |
5437 * Cleanup fragments created during evaluation of the | 5404 * Cleanup fragments created during evaluation of the |
5438 * "select" expression. | 5405 * "select" expression. |
5439 */ | 5406 */ |
5440 if (oldLocalFragmentTop != ctxt->localRVT) | 5407 if (oldLocalFragmentTop != ctxt->localRVT) |
5441 xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop); | 5408 xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop); |
5442 | |
5443 xpctxt->doc = oldXPContextDoc; | |
5444 xpctxt->node = oldXPContextNode; | |
5445 xpctxt->contextSize = oldXPContextSize; | |
5446 xpctxt->proximityPosition = oldXPProximityPosition; | |
5447 xpctxt->nsNr = oldXPNsNr; | |
5448 xpctxt->namespaces = oldXPNamespaces; | |
5449 } | 5409 } |
5450 | 5410 |
5451 #ifdef WITH_XSLT_DEBUG_PROCESS | 5411 #ifdef WITH_XSLT_DEBUG_PROCESS |
5452 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugContext, | 5412 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugContext, |
5453 "xsltIf: test evaluate to %d\n", res)); | 5413 "xsltIf: test evaluate to %d\n", res)); |
5454 #endif | 5414 #endif |
5455 | 5415 |
5456 if (res == -1) { | 5416 if (res == -1) { |
5457 ctxt->state = XSLT_STATE_STOPPED; | 5417 ctxt->state = XSLT_STATE_STOPPED; |
5458 goto error; | 5418 goto error; |
5459 } | 5419 } |
5460 if (res == 1) { | 5420 if (res == 1) { |
5461 /* | 5421 /* |
5462 * Instantiate the sequence constructor of xsl:if. | 5422 * Instantiate the sequence constructor of xsl:if. |
5463 */ | 5423 */ |
5464 xsltApplySequenceConstructor(ctxt, | 5424 xsltApplySequenceConstructor(ctxt, |
5465 contextNode, inst->children, NULL); | 5425 contextNode, inst->children, NULL); |
5466 } | 5426 } |
5467 | 5427 |
5468 #else /* XSLT_FAST_IF */ | 5428 #else /* XSLT_FAST_IF */ |
5469 { | 5429 { |
5470 xmlXPathObjectPtr xpobj = NULL; | |
5471 /* | 5430 /* |
5472 * OLD CODE: | 5431 * OLD CODE: |
5473 */ | 5432 */ |
5474 » { | 5433 » xmlXPathObjectPtr xpobj = xsltPreCompEval(ctxt, contextNode, comp); |
5475 » xmlXPathContextPtr xpctxt = ctxt->xpathCtxt; | |
5476 » xmlDocPtr oldXPContextDoc = xpctxt->doc; | |
5477 » xmlNsPtr *oldXPNamespaces = xpctxt->namespaces; | |
5478 » xmlNodePtr oldXPContextNode = xpctxt->node; | |
5479 » int oldXPProximityPosition = xpctxt->proximityPosition; | |
5480 » int oldXPContextSize = xpctxt->contextSize; | |
5481 » int oldXPNsNr = xpctxt->nsNr; | |
5482 | |
5483 » xpctxt->node = contextNode; | |
5484 » if (comp != NULL) { | |
5485 | |
5486 #ifdef XSLT_REFACTORED | |
5487 » » if (comp->inScopeNs != NULL) { | |
5488 » » xpctxt->namespaces = comp->inScopeNs->list; | |
5489 » » xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
5490 » » } else { | |
5491 » » xpctxt->namespaces = NULL; | |
5492 » » xpctxt->nsNr = 0; | |
5493 » » } | |
5494 #else | |
5495 » » xpctxt->namespaces = comp->nsList; | |
5496 » » xpctxt->nsNr = comp->nsNr; | |
5497 #endif | |
5498 » } else { | |
5499 » » xpctxt->namespaces = NULL; | |
5500 » » xpctxt->nsNr = 0; | |
5501 » } | |
5502 | |
5503 » /* | |
5504 » * This XPath function is optimized for boolean results. | |
5505 » */ | |
5506 » xpobj = xmlXPathCompiledEval(comp->comp, xpctxt); | |
5507 | |
5508 » xpctxt->doc = oldXPContextDoc; | |
5509 » xpctxt->node = oldXPContextNode; | |
5510 » xpctxt->contextSize = oldXPContextSize; | |
5511 » xpctxt->proximityPosition = oldXPProximityPosition; | |
5512 » xpctxt->nsNr = oldXPNsNr; | |
5513 » xpctxt->namespaces = oldXPNamespaces; | |
5514 » } | |
5515 if (xpobj != NULL) { | 5434 if (xpobj != NULL) { |
5516 if (xpobj->type != XPATH_BOOLEAN) | 5435 if (xpobj->type != XPATH_BOOLEAN) |
5517 xpobj = xmlXPathConvertBoolean(xpobj); | 5436 xpobj = xmlXPathConvertBoolean(xpobj); |
5518 if (xpobj->type == XPATH_BOOLEAN) { | 5437 if (xpobj->type == XPATH_BOOLEAN) { |
5519 res = xpobj->boolval; | 5438 res = xpobj->boolval; |
5520 | 5439 |
5521 #ifdef WITH_XSLT_DEBUG_PROCESS | 5440 #ifdef WITH_XSLT_DEBUG_PROCESS |
5522 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugC
ontext, | 5441 XSLT_TRACE(ctxt,XSLT_TRACE_IF,xsltGenericDebug(xsltGenericDebugC
ontext, |
5523 "xsltIf: test evaluate to %d\n", res)); | 5442 "xsltIf: test evaluate to %d\n", res)); |
5524 #endif | 5443 #endif |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5611 /* | 5530 /* |
5612 * The "current template rule" is cleared for the instantiation of | 5531 * The "current template rule" is cleared for the instantiation of |
5613 * xsl:for-each. | 5532 * xsl:for-each. |
5614 */ | 5533 */ |
5615 oldCurTemplRule = ctxt->currentTemplateRule; | 5534 oldCurTemplRule = ctxt->currentTemplateRule; |
5616 ctxt->currentTemplateRule = NULL; | 5535 ctxt->currentTemplateRule = NULL; |
5617 | 5536 |
5618 oldXPDoc = xpctxt->doc; | 5537 oldXPDoc = xpctxt->doc; |
5619 oldXPProximityPosition = xpctxt->proximityPosition; | 5538 oldXPProximityPosition = xpctxt->proximityPosition; |
5620 oldXPContextSize = xpctxt->contextSize; | 5539 oldXPContextSize = xpctxt->contextSize; |
5621 /* | |
5622 * Set up XPath. | |
5623 */ | |
5624 xpctxt->node = contextNode; | |
5625 #ifdef XSLT_REFACTORED | |
5626 if (comp->inScopeNs != NULL) { | |
5627 xpctxt->namespaces = comp->inScopeNs->list; | |
5628 xpctxt->nsNr = comp->inScopeNs->xpathNumber; | |
5629 } else { | |
5630 xpctxt->namespaces = NULL; | |
5631 xpctxt->nsNr = 0; | |
5632 } | |
5633 #else | |
5634 xpctxt->namespaces = comp->nsList; | |
5635 xpctxt->nsNr = comp->nsNr; | |
5636 #endif | |
5637 | 5540 |
5638 /* | 5541 /* |
5639 * Evaluate the 'select' expression. | 5542 * Evaluate the 'select' expression. |
5640 */ | 5543 */ |
5641 res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt); | 5544 res = xsltPreCompEval(ctxt, contextNode, comp); |
5642 | 5545 |
5643 if (res != NULL) { | 5546 if (res != NULL) { |
5644 if (res->type == XPATH_NODESET) | 5547 if (res->type == XPATH_NODESET) |
5645 list = res->nodesetval; | 5548 list = res->nodesetval; |
5646 else { | 5549 else { |
5647 xsltTransformError(ctxt, NULL, inst, | 5550 xsltTransformError(ctxt, NULL, inst, |
5648 "The 'select' expression does not evaluate to a node set.\n"); | 5551 "The 'select' expression does not evaluate to a node set.\n"); |
5649 | 5552 |
5650 #ifdef WITH_XSLT_DEBUG_PROCESS | 5553 #ifdef WITH_XSLT_DEBUG_PROCESS |
5651 XSLT_TRACE(ctxt,XSLT_TRACE_FOR_EACH,xsltGenericDebug(xsltGenericDebu
gContext, | 5554 XSLT_TRACE(ctxt,XSLT_TRACE_FOR_EACH,xsltGenericDebug(xsltGenericDebu
gContext, |
(...skipping 10 matching lines...) Expand all Loading... |
5662 | 5565 |
5663 if ((list == NULL) || (list->nodeNr <= 0)) | 5566 if ((list == NULL) || (list->nodeNr <= 0)) |
5664 goto exit; | 5567 goto exit; |
5665 | 5568 |
5666 #ifdef WITH_XSLT_DEBUG_PROCESS | 5569 #ifdef WITH_XSLT_DEBUG_PROCESS |
5667 XSLT_TRACE(ctxt,XSLT_TRACE_FOR_EACH,xsltGenericDebug(xsltGenericDebugContext
, | 5570 XSLT_TRACE(ctxt,XSLT_TRACE_FOR_EACH,xsltGenericDebug(xsltGenericDebugContext
, |
5668 "xsltForEach: select evaluates to %d nodes\n", list->nodeNr)); | 5571 "xsltForEach: select evaluates to %d nodes\n", list->nodeNr)); |
5669 #endif | 5572 #endif |
5670 | 5573 |
5671 /* | 5574 /* |
5672 * Restore XPath states for the "current node". | |
5673 */ | |
5674 xpctxt->contextSize = oldXPContextSize; | |
5675 xpctxt->proximityPosition = oldXPProximityPosition; | |
5676 xpctxt->node = contextNode; | |
5677 | |
5678 /* | |
5679 * Set the list; this has to be done already here for xsltDoSortFunction(). | 5575 * Set the list; this has to be done already here for xsltDoSortFunction(). |
5680 */ | 5576 */ |
5681 ctxt->nodeList = list; | 5577 ctxt->nodeList = list; |
5682 /* | 5578 /* |
5683 * Handle xsl:sort instructions and skip them for further processing. | 5579 * Handle xsl:sort instructions and skip them for further processing. |
5684 * BUG TODO: We are not using namespaced potentially defined on the | 5580 * BUG TODO: We are not using namespaced potentially defined on the |
5685 * xsl:sort element; XPath expression might fail. | 5581 * xsl:sort element; XPath expression might fail. |
5686 */ | 5582 */ |
5687 curInst = inst->children; | 5583 curInst = inst->children; |
5688 if (IS_XSLT_ELEM(curInst) && IS_XSLT_NAME(curInst, "sort")) { | 5584 if (IS_XSLT_ELEM(curInst) && IS_XSLT_NAME(curInst, "sort")) { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6069 goto error; | 5965 goto error; |
6070 res->dict = ctxt->dict; | 5966 res->dict = ctxt->dict; |
6071 xmlDictReference(res->dict); | 5967 xmlDictReference(res->dict); |
6072 | 5968 |
6073 #ifdef WITH_XSLT_DEBUG | 5969 #ifdef WITH_XSLT_DEBUG |
6074 xsltGenericDebug(xsltGenericDebugContext, | 5970 xsltGenericDebug(xsltGenericDebugContext, |
6075 "reusing transformation dict for output\n"); | 5971 "reusing transformation dict for output\n"); |
6076 #endif | 5972 #endif |
6077 } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { | 5973 } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { |
6078 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, | 5974 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, |
6079 » » "xsltApplyStylesheetInternal: unsupported method xhtml, using ht
ml\n", | 5975 » » "xsltApplyStylesheetInternal: unsupported method xhtml, using ht
ml\n"); |
6080 » » style->method); | |
6081 ctxt->type = XSLT_OUTPUT_HTML; | 5976 ctxt->type = XSLT_OUTPUT_HTML; |
6082 res = htmlNewDoc(doctypeSystem, doctypePublic); | 5977 res = htmlNewDoc(doctypeSystem, doctypePublic); |
6083 if (res == NULL) | 5978 if (res == NULL) |
6084 goto error; | 5979 goto error; |
6085 res->dict = ctxt->dict; | 5980 res->dict = ctxt->dict; |
6086 xmlDictReference(res->dict); | 5981 xmlDictReference(res->dict); |
6087 | 5982 |
6088 #ifdef WITH_XSLT_DEBUG | 5983 #ifdef WITH_XSLT_DEBUG |
6089 xsltGenericDebug(xsltGenericDebugContext, | 5984 xsltGenericDebug(xsltGenericDebugContext, |
6090 "reusing transformation dict for output\n"); | 5985 "reusing transformation dict for output\n"); |
6091 #endif | 5986 #endif |
6092 } else if (xmlStrEqual(method, (const xmlChar *) "text")) { | 5987 } else if (xmlStrEqual(method, (const xmlChar *) "text")) { |
6093 ctxt->type = XSLT_OUTPUT_TEXT; | 5988 ctxt->type = XSLT_OUTPUT_TEXT; |
6094 res = xmlNewDoc(style->version); | 5989 res = xmlNewDoc(style->version); |
6095 if (res == NULL) | 5990 if (res == NULL) |
6096 goto error; | 5991 goto error; |
6097 res->dict = ctxt->dict; | 5992 res->dict = ctxt->dict; |
6098 xmlDictReference(res->dict); | 5993 xmlDictReference(res->dict); |
6099 | 5994 |
6100 #ifdef WITH_XSLT_DEBUG | 5995 #ifdef WITH_XSLT_DEBUG |
6101 xsltGenericDebug(xsltGenericDebugContext, | 5996 xsltGenericDebug(xsltGenericDebugContext, |
6102 "reusing transformation dict for output\n"); | 5997 "reusing transformation dict for output\n"); |
6103 #endif | 5998 #endif |
6104 } else { | 5999 } else { |
6105 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, | 6000 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, |
6106 » » "xsltApplyStylesheetInternal: unsupported method %s\n", | 6001 » » "xsltApplyStylesheetInternal: unsupported method (%s)\n", |
6107 » » style->method); | 6002 » » method); |
6108 goto error; | 6003 goto error; |
6109 } | 6004 } |
6110 } else { | 6005 } else { |
6111 ctxt->type = XSLT_OUTPUT_XML; | 6006 ctxt->type = XSLT_OUTPUT_XML; |
6112 res = xmlNewDoc(style->version); | 6007 res = xmlNewDoc(style->version); |
6113 if (res == NULL) | 6008 if (res == NULL) |
6114 goto error; | 6009 goto error; |
6115 res->dict = ctxt->dict; | 6010 res->dict = ctxt->dict; |
6116 xmlDictReference(ctxt->dict); | 6011 xmlDictReference(ctxt->dict); |
6117 #ifdef WITH_XSLT_DEBUG | 6012 #ifdef WITH_XSLT_DEBUG |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6576 XSLT_NAMESPACE, | 6471 XSLT_NAMESPACE, |
6577 (xsltTransformFunction) xsltDebug); | 6472 (xsltTransformFunction) xsltDebug); |
6578 xsltRegisterExtElement(ctxt, (const xmlChar *) "otherwise", | 6473 xsltRegisterExtElement(ctxt, (const xmlChar *) "otherwise", |
6579 XSLT_NAMESPACE, | 6474 XSLT_NAMESPACE, |
6580 (xsltTransformFunction) xsltDebug); | 6475 (xsltTransformFunction) xsltDebug); |
6581 xsltRegisterExtElement(ctxt, (const xmlChar *) "fallback", | 6476 xsltRegisterExtElement(ctxt, (const xmlChar *) "fallback", |
6582 XSLT_NAMESPACE, | 6477 XSLT_NAMESPACE, |
6583 (xsltTransformFunction) xsltDebug); | 6478 (xsltTransformFunction) xsltDebug); |
6584 | 6479 |
6585 } | 6480 } |
OLD | NEW |