ReactOS 0.4.16-dev-334-g4d9f67c
templates.c File Reference
#include "precomp.h"
#include <libxml/globals.h>
Include dependency graph for templates.c:

Go to the source code of this file.

Functions

int xsltEvalXPathPredicate (xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp, xmlNsPtr *nsList, int nsNr)
 
xmlCharxsltEvalXPathStringNs (xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp, int nsNr, xmlNsPtr *nsList)
 
xmlCharxsltEvalXPathString (xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp)
 
xmlCharxsltEvalTemplateString (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst)
 
xmlCharxsltAttrTemplateValueProcessNode (xsltTransformContextPtr ctxt, const xmlChar *str, xmlNodePtr inst)
 
xmlCharxsltAttrTemplateValueProcess (xsltTransformContextPtr ctxt, const xmlChar *str)
 
: the attribute QName

xsltEvalAttrValueTemplate: @ctxt: the XSLT transformation context @inst: the instruction (or LRE) in the stylesheet holding the attribute with an AVT

@ns: the attribute namespace URI

Evaluate a attribute value template, i.e. the attribute value can contain expressions contained in curly braces ({}) and those are substituted by they computed value.

Returns the computed string value or NULL, must be deallocated by the caller.

xmlCharxsltEvalAttrValueTemplate (xsltTransformContextPtr ctxt, xmlNodePtr inst, const xmlChar *name, const xmlChar *ns)
 
: the attribute Name

xsltEvalStaticAttrValueTemplate: @style: the XSLT stylesheet @inst: the instruction (or LRE) in the stylesheet holding the attribute with an AVT

@ns: the attribute namespace URI @found: indicator whether the attribute is present

Check if an attribute value template has a static value, i.e. the attribute value does not contain expressions contained in curly braces ({})

Returns the static string value or NULL, must be deallocated by the caller.

const xmlCharxsltEvalStaticAttrValueTemplate (xsltStylesheetPtr style, xmlNodePtr inst, const xmlChar *name, const xmlChar *ns, int *found)
 
xmlAttrPtr xsltAttrTemplateProcess (xsltTransformContextPtr ctxt, xmlNodePtr target, xmlAttrPtr attr)
 
xmlAttrPtr xsltAttrListTemplateProcess (xsltTransformContextPtr ctxt, xmlNodePtr target, xmlAttrPtr attrs)
 
xmlNodePtrxsltTemplateProcess (xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, xmlNodePtr node)
 

Function Documentation

◆ xsltAttrListTemplateProcess()

xmlAttrPtr xsltAttrListTemplateProcess ( xsltTransformContextPtr  ctxt,
xmlNodePtr  target,
xmlAttrPtr  attrs 
)

xsltAttrListTemplateProcess: @ctxt: the XSLT transformation context @target: the element where the attributes will be grafted @attrs: the first attribute

Processes all attributes of a Literal Result Element. Attribute references are applied via xsl:use-attribute-set attributes. Copies all non XSLT-attributes over to the @target element and evaluates Attribute Value Templates.

Called by xsltApplySequenceConstructor() (transform.c).

Returns a new list of attribute nodes, or NULL in case of error. (Don't assign the result to @target->properties; if the result is NULL, you'll get memory leaks, since the attributes will be disattached.)

Definition at line 635 of file templates.c.

637{
639 xmlNodePtr oldInsert, text;
640 xmlNsPtr origNs = NULL, copyNs = NULL;
641 const xmlChar *value;
642 xmlChar *valueAVT;
643 int hasAttr = 0;
644
645 if ((ctxt == NULL) || (target == NULL) || (attrs == NULL) ||
646 (target->type != XML_ELEMENT_NODE))
647 return(NULL);
648
649 oldInsert = ctxt->insert;
650 ctxt->insert = target;
651
652 /*
653 * Apply attribute-sets.
654 */
655 attr = attrs;
656 do {
657#ifdef XSLT_REFACTORED
658 if ((attr->psvi == xsltXSLTAttrMarker) &&
659 xmlStrEqual(attr->name, (const xmlChar *)"use-attribute-sets"))
660 {
662 }
663#else
664 if ((attr->ns != NULL) &&
665 xmlStrEqual(attr->name, (const xmlChar *)"use-attribute-sets") &&
666 xmlStrEqual(attr->ns->href, XSLT_NAMESPACE))
667 {
669 }
670#endif
671 attr = attr->next;
672 } while (attr != NULL);
673
674 if (target->properties != NULL) {
675 hasAttr = 1;
676 }
677
678 /*
679 * Instantiate LRE-attributes.
680 */
681 attr = attrs;
682 do {
683 /*
684 * Skip XSLT attributes.
685 */
686#ifdef XSLT_REFACTORED
687 if (attr->psvi == xsltXSLTAttrMarker) {
688 goto next_attribute;
689 }
690#else
691 if ((attr->ns != NULL) &&
692 xmlStrEqual(attr->ns->href, XSLT_NAMESPACE))
693 {
694 goto next_attribute;
695 }
696#endif
697 /*
698 * Get the value.
699 */
700 if (attr->children != NULL) {
701 if ((attr->children->type != XML_TEXT_NODE) ||
702 (attr->children->next != NULL))
703 {
704 xsltTransformError(ctxt, NULL, attr->parent,
705 "Internal error: The children of an attribute node of a "
706 "literal result element are not in the expected form.\n");
707 goto error;
708 }
709 value = attr->children->content;
710 if (value == NULL)
711 value = xmlDictLookup(ctxt->dict, BAD_CAST "", 0);
712 } else
713 value = xmlDictLookup(ctxt->dict, BAD_CAST "", 0);
714
715 /*
716 * Get the namespace. Avoid lookups of same namespaces.
717 */
718 if (attr->ns != origNs) {
719 origNs = attr->ns;
720 if (attr->ns != NULL) {
721#ifdef XSLT_REFACTORED
722 copyNs = xsltGetSpecialNamespace(ctxt, attr->parent,
723 attr->ns->href, attr->ns->prefix, target);
724#else
725 copyNs = xsltGetNamespace(ctxt, attr->parent,
726 attr->ns, target);
727#endif
728 if (copyNs == NULL)
729 goto error;
730 } else
731 copyNs = NULL;
732 }
733 /*
734 * Create a new attribute.
735 */
736 if (hasAttr) {
737 copy = xmlSetNsProp(target, copyNs, attr->name, NULL);
738 } else {
739 /*
740 * Avoid checking for duplicate attributes if there aren't
741 * any attribute sets.
742 */
744
745 if (copy != NULL) {
746 copy->ns = copyNs;
747
748 /*
749 * Attach it to the target element.
750 */
751 copy->parent = target;
752 if (last == NULL) {
753 target->properties = copy;
754 last = copy;
755 } else {
756 last->next = copy;
757 copy->prev = last;
758 last = copy;
759 }
760 }
761 }
762 if (copy == NULL) {
763 if (attr->ns) {
764 xsltTransformError(ctxt, NULL, attr->parent,
765 "Internal error: Failed to create attribute '{%s}%s'.\n",
766 attr->ns->href, attr->name);
767 } else {
768 xsltTransformError(ctxt, NULL, attr->parent,
769 "Internal error: Failed to create attribute '%s'.\n",
770 attr->name);
771 }
772 goto error;
773 }
774
775 /*
776 * Set the value.
777 */
779 if (text != NULL) {
780 copy->last = copy->children = text;
781 text->parent = (xmlNodePtr) copy;
782 text->doc = copy->doc;
783
784 if (attr->psvi != NULL) {
785 /*
786 * Evaluate the Attribute Value Template.
787 */
788 valueAVT = xsltEvalAVT(ctxt, attr->psvi, attr->parent);
789 if (valueAVT == NULL) {
790 /*
791 * TODO: Damn, we need an easy mechanism to report
792 * qualified names!
793 */
794 if (attr->ns) {
795 xsltTransformError(ctxt, NULL, attr->parent,
796 "Internal error: Failed to evaluate the AVT "
797 "of attribute '{%s}%s'.\n",
798 attr->ns->href, attr->name);
799 } else {
800 xsltTransformError(ctxt, NULL, attr->parent,
801 "Internal error: Failed to evaluate the AVT "
802 "of attribute '%s'.\n",
803 attr->name);
804 }
805 text->content = xmlStrdup(BAD_CAST "");
806 goto error;
807 } else {
808 text->content = valueAVT;
809 }
810 } else if ((ctxt->internalized) &&
811 (target->doc != NULL) &&
812 (target->doc->dict == ctxt->dict) &&
813 xmlDictOwns(ctxt->dict, value))
814 {
815 text->content = (xmlChar *) value;
816 } else {
817 text->content = xmlStrdup(value);
818 }
819 if ((copy != NULL) && (text != NULL) &&
820 (xmlIsID(copy->doc, copy->parent, copy)))
821 xmlAddID(NULL, copy->doc, text->content, copy);
822 }
823
825 attr = attr->next;
826 } while (attr != NULL);
827
828 ctxt->insert = oldInsert;
829 return(target->properties);
830
831error:
832 ctxt->insert = oldInsert;
833 return(NULL);
834}
xmlChar * xsltEvalAVT(xsltTransformContextPtr ctxt, void *avt, xmlNodePtr node)
Definition: attrvt.c:356
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define NULL
Definition: types.h:112
void xsltApplyAttributeSet(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, const xmlChar *attrSets)
Definition: attributes.c:1086
const WCHAR * text
Definition: package.c:1794
GLenum target
Definition: glext.h:7315
#define error(str)
Definition: mkdosfs.c:1605
static UINT UINT last
Definition: font.c:45
#define next_attribute(a)
Definition: reader.c:252
xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, const xmlChar *nsName, const xmlChar *nsPrefix, xmlNodePtr target)
Definition: namespaces.c:299
xmlNsPtr xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, xmlNodePtr out)
Definition: namespaces.c:596
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
Definition: dict.c:867
XMLPUBFUN int XMLCALL xmlDictOwns(xmlDictPtr dict, const xmlChar *str)
Definition: dict.c:1220
xmlNode * xmlNodePtr
Definition: tree.h:488
XMLPUBFUN xmlAttrPtr XMLCALL xmlNewDocProp(xmlDocPtr doc, const xmlChar *name, const xmlChar *value)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewText(const xmlChar *content)
@ XML_TEXT_NODE
Definition: tree.h:162
@ XML_ELEMENT_NODE
Definition: tree.h:160
Definition: tree.h:434
Definition: tree.h:489
Definition: tree.h:389
Definition: cookie.c:202
WCHAR * name
Definition: cookie.c:203
Definition: pdh_main.c:94
XMLPUBFUN xmlIDPtr XMLCALL xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, xmlAttrPtr attr)
Definition: valid.c:2672
XMLPUBFUN int XMLCALL xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr)
Definition: valid.c:2774
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:160
unsigned char xmlChar
Definition: xmlstring.h:28
#define XSLT_NAMESPACE
Definition: xslt.h:46
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678

Referenced by xsltApplySequenceConstructor().

◆ xsltAttrTemplateProcess()

xmlAttrPtr xsltAttrTemplateProcess ( xsltTransformContextPtr  ctxt,
xmlNodePtr  target,
xmlAttrPtr  attr 
)

xsltAttrTemplateProcess: @ctxt: the XSLT transformation context @target: the element where the attribute will be grafted @attr: the attribute node of a literal result element

Process one attribute of a Literal Result Element (in the stylesheet). Evaluates Attribute Value Templates and copies the attribute over to the result element. This does not process attribute sets (xsl:use-attribute-set).

Returns the generated attribute node.

Definition at line 479 of file templates.c.

481{
482 const xmlChar *value;
484
485 if ((ctxt == NULL) || (attr == NULL) || (target == NULL) ||
486 (target->type != XML_ELEMENT_NODE))
487 return(NULL);
488
489 if (attr->type != XML_ATTRIBUTE_NODE)
490 return(NULL);
491
492 /*
493 * Skip all XSLT attributes.
494 */
495#ifdef XSLT_REFACTORED
496 if (attr->psvi == xsltXSLTAttrMarker)
497 return(NULL);
498#else
499 if ((attr->ns != NULL) && xmlStrEqual(attr->ns->href, XSLT_NAMESPACE))
500 return(NULL);
501#endif
502 /*
503 * Get the value.
504 */
505 if (attr->children != NULL) {
506 if ((attr->children->type != XML_TEXT_NODE) ||
507 (attr->children->next != NULL))
508 {
509 xsltTransformError(ctxt, NULL, attr->parent,
510 "Internal error: The children of an attribute node of a "
511 "literal result element are not in the expected form.\n");
512 return(NULL);
513 }
514 value = attr->children->content;
515 if (value == NULL)
516 value = xmlDictLookup(ctxt->dict, BAD_CAST "", 0);
517 } else
518 value = xmlDictLookup(ctxt->dict, BAD_CAST "", 0);
519 /*
520 * Overwrite duplicates.
521 */
522 ret = target->properties;
523 while (ret != NULL) {
524 if (((attr->ns != NULL) == (ret->ns != NULL)) &&
525 xmlStrEqual(ret->name, attr->name) &&
526 ((attr->ns == NULL) || xmlStrEqual(ret->ns->href, attr->ns->href)))
527 {
528 break;
529 }
530 ret = ret->next;
531 }
532 if (ret != NULL) {
533 /* free the existing value */
534 xmlFreeNodeList(ret->children);
535 ret->children = ret->last = NULL;
536 /*
537 * Adjust ns-prefix if needed.
538 */
539 if ((ret->ns != NULL) &&
540 (! xmlStrEqual(ret->ns->prefix, attr->ns->prefix)))
541 {
542 ret->ns = xsltGetNamespace(ctxt, attr->parent, attr->ns, target);
543 }
544 } else {
545 /* create a new attribute */
546 if (attr->ns != NULL)
548 xsltGetNamespace(ctxt, attr->parent, attr->ns, target),
549 attr->name, NULL);
550 else
552 }
553 /*
554 * Set the value.
555 */
556 if (ret != NULL) {
558
560 if (text != NULL) {
561 ret->last = ret->children = text;
562 text->parent = (xmlNodePtr) ret;
563 text->doc = ret->doc;
564
565 if (attr->psvi != NULL) {
566 /*
567 * Evaluate the Attribute Value Template.
568 */
569 xmlChar *val;
570 val = xsltEvalAVT(ctxt, attr->psvi, attr->parent);
571 if (val == NULL) {
572 /*
573 * TODO: Damn, we need an easy mechanism to report
574 * qualified names!
575 */
576 if (attr->ns) {
577 xsltTransformError(ctxt, NULL, attr->parent,
578 "Internal error: Failed to evaluate the AVT "
579 "of attribute '{%s}%s'.\n",
580 attr->ns->href, attr->name);
581 } else {
582 xsltTransformError(ctxt, NULL, attr->parent,
583 "Internal error: Failed to evaluate the AVT "
584 "of attribute '%s'.\n",
585 attr->name);
586 }
587 text->content = xmlStrdup(BAD_CAST "");
588 } else {
589 text->content = val;
590 }
591 } else if ((ctxt->internalized) && (target != NULL) &&
592 (target->doc != NULL) &&
593 (target->doc->dict == ctxt->dict) &&
594 xmlDictOwns(ctxt->dict, value)) {
595 text->content = (xmlChar *) value;
596 } else {
597 text->content = xmlStrdup(value);
598 }
599 }
600 } else {
601 if (attr->ns) {
602 xsltTransformError(ctxt, NULL, attr->parent,
603 "Internal error: Failed to create attribute '{%s}%s'.\n",
604 attr->ns->href, attr->name);
605 } else {
606 xsltTransformError(ctxt, NULL, attr->parent,
607 "Internal error: Failed to create attribute '%s'.\n",
608 attr->name);
609 }
610 }
611 return(ret);
612}
GLuint GLfloat * val
Definition: glext.h:7180
@ XML_ATTRIBUTE_NODE
Definition: tree.h:161
XMLPUBFUN void XMLCALL xmlFreeNodeList(xmlNodePtr cur)
XMLPUBFUN xmlAttrPtr XMLCALL xmlNewNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, const xmlChar *value)
int ret

◆ xsltAttrTemplateValueProcess()

xmlChar * xsltAttrTemplateValueProcess ( xsltTransformContextPtr  ctxt,
const xmlChar str 
)

xsltAttrTemplateValueProcess: @ctxt: the XSLT transformation context @str: the attribute template node value

Process the given node and return the new string value.

Returns the computed string value or NULL, must be deallocated by the caller.

Definition at line 372 of file templates.c.

372 {
374}
const WCHAR * str
xmlChar * xsltAttrTemplateValueProcessNode(xsltTransformContextPtr ctxt, const xmlChar *str, xmlNodePtr inst)
Definition: templates.c:260

◆ xsltAttrTemplateValueProcessNode()

xmlChar * xsltAttrTemplateValueProcessNode ( xsltTransformContextPtr  ctxt,
const xmlChar str,
xmlNodePtr  inst 
)

xsltAttrTemplateValueProcessNode: @ctxt: the XSLT transformation context @str: the attribute template node value @inst: the instruction (or LRE) in the stylesheet holding the attribute with an AVT

Process the given string, allowing to pass a namespace mapping context and return the new string value.

Called by:

QUESTION: Why is this function public? It is not used outside of templates.c.

Returns the computed string value or NULL, must be deallocated by the caller.

Definition at line 260 of file templates.c.

262{
263 xmlChar *ret = NULL;
264 const xmlChar *cur;
265 xmlChar *expr, *val;
266 xmlNsPtr *nsList = NULL;
267 int nsNr = 0;
268
269 if (str == NULL) return(NULL);
270 if (*str == 0)
271 return(xmlStrndup((xmlChar *)"", 0));
272
273 cur = str;
274 while (*cur != 0) {
275 if (*cur == '{') {
276 if (*(cur+1) == '{') { /* escaped '{' */
277 cur++;
278 ret = xmlStrncat(ret, str, cur - str);
279 cur++;
280 str = cur;
281 continue;
282 }
283 ret = xmlStrncat(ret, str, cur - str);
284 str = cur;
285 cur++;
286 while ((*cur != 0) && (*cur != '}')) {
287 /* Need to check for literal (bug539741) */
288 if ((*cur == '\'') || (*cur == '"')) {
289 char delim = *(cur++);
290 while ((*cur != 0) && (*cur != delim))
291 cur++;
292 if (*cur != 0)
293 cur++; /* skip the ending delimiter */
294 } else
295 cur++;
296 }
297 if (*cur == 0) {
298 xsltTransformError(ctxt, NULL, inst,
299 "xsltAttrTemplateValueProcessNode: unmatched '{'\n");
300 ret = xmlStrncat(ret, str, cur - str);
301 goto exit;
302 }
303 str++;
304 expr = xmlStrndup(str, cur - str);
305 if (expr == NULL)
306 goto exit;
307 else if (*expr == '{') {
308 ret = xmlStrcat(ret, expr);
309 xmlFree(expr);
310 } else {
311 xmlXPathCompExprPtr comp;
312 /*
313 * TODO: keep precompiled form around
314 */
315 if ((nsList == NULL) && (inst != NULL)) {
316 int i = 0;
317
318 nsList = xmlGetNsList(inst->doc, inst);
319 if (nsList != NULL) {
320 while (nsList[i] != NULL)
321 i++;
322 nsNr = i;
323 }
324 }
325 comp = xmlXPathCtxtCompile(ctxt->xpathCtxt, expr);
326 val = xsltEvalXPathStringNs(ctxt, comp, nsNr, nsList);
327 xmlXPathFreeCompExpr(comp);
328 xmlFree(expr);
329 if (val != NULL) {
330 ret = xmlStrcat(ret, val);
331 xmlFree(val);
332 }
333 }
334 cur++;
335 str = cur;
336 } else if (*cur == '}') {
337 cur++;
338 if (*cur == '}') { /* escaped '}' */
339 ret = xmlStrncat(ret, str, cur - str);
340 cur++;
341 str = cur;
342 continue;
343 } else {
344 xsltTransformError(ctxt, NULL, inst,
345 "xsltAttrTemplateValueProcessNode: unmatched '}'\n");
346 }
347 } else
348 cur++;
349 }
350 if (cur != str) {
351 ret = xmlStrncat(ret, str, cur - str);
352 }
353
354exit:
355 if (nsList != NULL)
356 xmlFree(nsList);
357
358 return(ret);
359}
FxCollectionEntry * cur
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
#define exit(n)
Definition: config.h:202
struct _xmlDoc * doc
Definition: tree.h:498
xmlXPathContextPtr xpathCtxt
Definition: query.h:86
xmlChar * xsltEvalXPathStringNs(xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp, int nsNr, xmlNsPtr *nsList)
Definition: templates.c:105
XMLPUBFUN xmlChar *XMLCALL xmlStrndup(const xmlChar *cur, int len)
Definition: xmlstring.c:42
XMLPUBFUN xmlChar *XMLCALL xmlStrcat(xmlChar *cur, const xmlChar *add)
Definition: xmlstring.c:524
XMLPUBFUN xmlChar *XMLCALL xmlStrncat(xmlChar *cur, const xmlChar *add, int len)
Definition: xmlstring.c:446

Referenced by xsltAttrTemplateValueProcess(), and xsltEvalAttrValueTemplate().

◆ xsltEvalAttrValueTemplate()

xmlChar * xsltEvalAttrValueTemplate ( xsltTransformContextPtr  ctxt,
xmlNodePtr  inst,
const xmlChar name,
const xmlChar ns 
)

Definition at line 392 of file templates.c.

394{
395 xmlChar *ret;
396 xmlChar *expr;
397
398 if ((ctxt == NULL) || (inst == NULL) || (name == NULL) ||
399 (inst->type != XML_ELEMENT_NODE))
400 return(NULL);
401
402 expr = xsltGetNsProp(inst, name, ns);
403 if (expr == NULL)
404 return(NULL);
405
406 /*
407 * TODO: though now {} is detected ahead, it would still be good to
408 * optimize both functions to keep the splitted value if the
409 * attribute content and the XPath precompiled expressions around
410 */
411
413#ifdef WITH_XSLT_DEBUG_TEMPLATES
415 "xsltEvalAttrValueTemplate: %s returns %s\n", expr, ret));
416#endif
417 if (expr != NULL)
418 xmlFree(expr);
419 return(ret);
420}
xmlElementType type
Definition: tree.h:491
Definition: name.c:39
Definition: mxnamespace.c:45
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
void * xsltGenericDebugContext
Definition: xsltutils.c:549
xmlChar * xsltGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace)
Definition: xsltutils.c:142
@ XSLT_TRACE_TEMPLATES
Definition: xsltutils.h:115
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:125

Referenced by xsltAttribute(), xsltDefaultSortFunction(), xsltDocumentElem(), xsltElement(), xsltNumberFormat(), and xsltProcessingInstruction().

◆ xsltEvalStaticAttrValueTemplate()

const xmlChar * xsltEvalStaticAttrValueTemplate ( xsltStylesheetPtr  style,
xmlNodePtr  inst,
const xmlChar name,
const xmlChar ns,
int found 
)

Definition at line 438 of file templates.c.

439 {
440 const xmlChar *ret;
441 xmlChar *expr;
442
443 if ((style == NULL) || (inst == NULL) || (name == NULL) ||
444 (inst->type != XML_ELEMENT_NODE))
445 return(NULL);
446
447 expr = xsltGetNsProp(inst, name, ns);
448 if (expr == NULL) {
449 *found = 0;
450 return(NULL);
451 }
452 *found = 1;
453
454 ret = xmlStrchr(expr, '{');
455 if (ret != NULL) {
456 xmlFree(expr);
457 return(NULL);
458 }
459 ret = xmlDictLookup(style->dict, expr, -1);
460 xmlFree(expr);
461 return(ret);
462}
Arabic default style
Definition: afstyles.h:94
XMLPUBFUN const xmlChar *XMLCALL xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:325

Referenced by xsltAttributeComp(), xsltDocumentComp(), xsltElementComp(), xsltNumberComp(), xsltProcessingInstructionComp(), and xsltSortComp().

◆ xsltEvalTemplateString()

xmlChar * xsltEvalTemplateString ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst 
)

xsltEvalTemplateString: @ctxt: the XSLT transformation context @contextNode: the current node in the source tree @inst: the XSLT instruction (xsl:comment, xsl:processing-instruction)

Processes the sequence constructor of the given instruction on @contextNode and converts the resulting tree to a string. This is needed by e.g. xsl:comment and xsl:processing-instruction.

Returns the computed string value or NULL; it's up to the caller to free the result.

Definition at line 189 of file templates.c.

192{
193 xmlNodePtr oldInsert, insert = NULL;
194 xmlChar *ret;
195 const xmlChar *oldLastText;
196 int oldLastTextSize, oldLastTextUse;
197
198 if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL) ||
199 (inst->type != XML_ELEMENT_NODE))
200 return(NULL);
201
202 if (inst->children == NULL)
203 return(NULL);
204
205 /*
206 * This creates a temporary element-node to add the resulting
207 * text content to.
208 * OPTIMIZE TODO: Keep such an element-node in the transformation
209 * context to avoid creating it every time.
210 */
212 (const xmlChar *)"fake", NULL);
213 if (insert == NULL) {
214 xsltTransformError(ctxt, NULL, contextNode,
215 "Failed to create temporary node\n");
216 return(NULL);
217 }
218 oldInsert = ctxt->insert;
219 ctxt->insert = insert;
220 oldLastText = ctxt->lasttext;
221 oldLastTextSize = ctxt->lasttsize;
222 oldLastTextUse = ctxt->lasttuse;
223 /*
224 * OPTIMIZE TODO: if inst->children consists only of text-nodes.
225 */
226 xsltApplyOneTemplate(ctxt, contextNode, inst->children, NULL, NULL);
227
228 ctxt->insert = oldInsert;
229 ctxt->lasttext = oldLastText;
230 ctxt->lasttsize = oldLastTextSize;
231 ctxt->lasttuse = oldLastTextUse;
232
234 if (insert != NULL)
236 return(ret);
237}
void xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ ATTRIBUTE_UNUSED, xsltStackElemPtr params)
Definition: transform.c:3273
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetContent(const xmlNode *cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content)
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
struct _xmlNode * children
Definition: tree.h:493
const xmlChar * lasttext
static int insert
Definition: xmllint.c:138

Referenced by xsltAttribute(), xsltComment(), xsltMessage(), and xsltProcessingInstruction().

◆ xsltEvalXPathPredicate()

int xsltEvalXPathPredicate ( xsltTransformContextPtr  ctxt,
xmlXPathCompExprPtr  comp,
xmlNsPtr nsList,
int  nsNr 
)

xsltEvalXPathPredicate: @ctxt: the XSLT transformation context @comp: the XPath compiled expression @nsList: the namespaces in scope @nsNr: the number of namespaces in scope

Process the expression using XPath and evaluate the result as an XPath predicate

Returns 1 is the predicate was true, 0 otherwise

Definition at line 39 of file templates.c.

40 {
41 int ret;
42 xmlXPathObjectPtr res;
43 int oldNsNr;
44 xmlNsPtr *oldNamespaces;
45 xmlNodePtr oldInst;
46 int oldProximityPosition, oldContextSize;
47
48 if ((ctxt == NULL) || (ctxt->inst == NULL)) {
50 "xsltEvalXPathPredicate: No context or instruction\n");
51 return(0);
52 }
53
54 oldContextSize = ctxt->xpathCtxt->contextSize;
55 oldProximityPosition = ctxt->xpathCtxt->proximityPosition;
56 oldNsNr = ctxt->xpathCtxt->nsNr;
57 oldNamespaces = ctxt->xpathCtxt->namespaces;
58 oldInst = ctxt->inst;
59
60 ctxt->xpathCtxt->node = ctxt->node;
61 ctxt->xpathCtxt->namespaces = nsList;
62 ctxt->xpathCtxt->nsNr = nsNr;
63
64 res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt);
65
66 if (res != NULL) {
67 ret = xmlXPathEvalPredicate(ctxt->xpathCtxt, res);
68 xmlXPathFreeObject(res);
69#ifdef WITH_XSLT_DEBUG_TEMPLATES
71 "xsltEvalXPathPredicate: returns %d\n", ret));
72#endif
73 } else {
74#ifdef WITH_XSLT_DEBUG_TEMPLATES
76 "xsltEvalXPathPredicate: failed\n"));
77#endif
79 ret = 0;
80 }
81 ctxt->xpathCtxt->nsNr = oldNsNr;
82
83 ctxt->xpathCtxt->namespaces = oldNamespaces;
84 ctxt->inst = oldInst;
85 ctxt->xpathCtxt->contextSize = oldContextSize;
86 ctxt->xpathCtxt->proximityPosition = oldProximityPosition;
87
88 return(ret);
89}
GLuint res
Definition: glext.h:9613
xsltTransformState state
@ XSLT_STATE_STOPPED

Referenced by xsltTestPredicateMatch().

◆ xsltEvalXPathString()

xmlChar * xsltEvalXPathString ( xsltTransformContextPtr  ctxt,
xmlXPathCompExprPtr  comp 
)

xsltEvalXPathString: @ctxt: the XSLT transformation context @comp: the compiled XPath expression

Process the expression using XPath and get a string

Returns the computed string value or NULL, must be deallocated by the caller.

Definition at line 171 of file templates.c.

171 {
172 return(xsltEvalXPathStringNs(ctxt, comp, 0, NULL));
173}

Referenced by xsltDocumentElem().

◆ xsltEvalXPathStringNs()

xmlChar * xsltEvalXPathStringNs ( xsltTransformContextPtr  ctxt,
xmlXPathCompExprPtr  comp,
int  nsNr,
xmlNsPtr nsList 
)

xsltEvalXPathStringNs: @ctxt: the XSLT transformation context @comp: the compiled XPath expression @nsNr: the number of namespaces in the list @nsList: the list of in-scope namespaces to use

Process the expression using XPath, allowing to pass a namespace mapping context and get a string

Returns the computed string value or NULL, must be deallocated by the caller.

Definition at line 105 of file templates.c.

106 {
107 xmlChar *ret = NULL;
108 xmlXPathObjectPtr res;
109 xmlNodePtr oldInst;
110 xmlNodePtr oldNode;
111 int oldPos, oldSize;
112 int oldNsNr;
113 xmlNsPtr *oldNamespaces;
114
115 if ((ctxt == NULL) || (ctxt->inst == NULL)) {
117 "xsltEvalXPathStringNs: No context or instruction\n");
118 return(0);
119 }
120
121 oldInst = ctxt->inst;
122 oldNode = ctxt->node;
123 oldPos = ctxt->xpathCtxt->proximityPosition;
124 oldSize = ctxt->xpathCtxt->contextSize;
125 oldNsNr = ctxt->xpathCtxt->nsNr;
126 oldNamespaces = ctxt->xpathCtxt->namespaces;
127
128 ctxt->xpathCtxt->node = ctxt->node;
129 /* TODO: do we need to propagate the namespaces here ? */
130 ctxt->xpathCtxt->namespaces = nsList;
131 ctxt->xpathCtxt->nsNr = nsNr;
132 res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt);
133 if (res != NULL) {
134 if (res->type != XPATH_STRING)
135 res = xmlXPathConvertString(res);
136 if (res->type == XPATH_STRING) {
137 ret = res->stringval;
138 res->stringval = NULL;
139 } else {
141 "xpath : string() function didn't return a String\n");
142 }
143 xmlXPathFreeObject(res);
144 } else {
146 }
147#ifdef WITH_XSLT_DEBUG_TEMPLATES
149 "xsltEvalXPathString: returns %s\n", ret));
150#endif
151 ctxt->inst = oldInst;
152 ctxt->node = oldNode;
153 ctxt->xpathCtxt->contextSize = oldSize;
154 ctxt->xpathCtxt->proximityPosition = oldPos;
155 ctxt->xpathCtxt->nsNr = oldNsNr;
156 ctxt->xpathCtxt->namespaces = oldNamespaces;
157 return(ret);
158}

Referenced by xsltAttrTemplateValueProcessNode(), xsltEvalAVT(), and xsltEvalXPathString().

◆ xsltTemplateProcess()

xmlNodePtr * xsltTemplateProcess ( xsltTransformContextPtr ctxt  ATTRIBUTE_UNUSED,
xmlNodePtr  node 
)

xsltTemplateProcess: @ctxt: the XSLT transformation context @node: the attribute template node

Obsolete. Don't use it.

Returns NULL.

Definition at line 847 of file templates.c.

847 {
848 if (node == NULL)
849 return(NULL);
850
851 return(0);
852}
Definition: dlist.c:348