ReactOS  0.4.15-dev-1367-g07cc0b5
transform.c File Reference
#include "precomp.h"
#include <libxml/debugXML.h>
Include dependency graph for transform.c:

Go to the source code of this file.

Classes

struct  xsltHTMLVersion
 

Macros

#define XSLT_GENERATE_HTML_DOCTYPE
 
#define FALSE   (0 == 1)
 
#define TRUE   (!FALSE)
 
#define IS_BLANK_NODE(n)   (((n)->type == XML_TEXT_NODE) && (xsltIsBlank((n)->content)))
 

Typedefs

typedef struct xsltHTMLVersion xsltHTMLVersion
 

Functions

static int xsltGetHTMLIDs (const xmlChar *version, const xmlChar **publicID, const xmlChar **systemID)
 
static xmlNsPtr xsltCopyNamespaceListInternal (xmlNodePtr node, xmlNsPtr cur)
 
static xmlNodePtr xsltCopyTree (xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr node, xmlNodePtr insert, int isLRE, int topElemVisited)
 
static void xsltApplySequenceConstructor (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
 
static void xsltApplyXSLTTemplate (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ, xsltStackElemPtr withParams)
 
static int templPush (xsltTransformContextPtr ctxt, xsltTemplatePtr value)
 
static xsltTemplatePtr templPop (xsltTransformContextPtr ctxt)
 
void xsltLocalVariablePop (xsltTransformContextPtr ctxt, int limitNr, int level)
 
static void xsltTemplateParamsCleanup (xsltTransformContextPtr ctxt)
 
static xmlXPathObjectPtr xsltPreCompEval (xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
 
static int xsltPreCompEvalToBoolean (xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
 
void xsltSetXIncludeDefault (int xinclude)
 
int xsltGetXIncludeDefault (void)
 
void xsltDebugSetDefaultTrace (xsltDebugTraceCodes val)
 
xsltDebugTraceCodes xsltDebugGetDefaultTrace ()
 
static xsltTransformCachePtr xsltTransformCacheCreate (void)
 
static void xsltTransformCacheFree (xsltTransformCachePtr cache)
 
xsltTransformContextPtr xsltNewTransformContext (xsltStylesheetPtr style, xmlDocPtr doc)
 
void xsltFreeTransformContext (xsltTransformContextPtr ctxt)
 
static xmlNodePtr xsltAddChild (xmlNodePtr parent, xmlNodePtr cur)
 
static xmlNodePtr xsltAddTextString (xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int len)
 
xmlNodePtr xsltCopyTextString (xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int noescape)
 
static xmlNodePtr xsltCopyText (xsltTransformContextPtr ctxt, xmlNodePtr target, xmlNodePtr cur, int interned)
 
static xmlAttrPtr xsltShallowCopyAttr (xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr target, xmlAttrPtr attr)
 
static int xsltCopyAttrListNoOverwrite (xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr target, xmlAttrPtr attr)
 
static xmlNodePtr xsltShallowCopyElem (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr insert, int isLRE)
 
static xmlNodePtr xsltCopyTreeList (xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr list, xmlNodePtr insert, int isLRE, int topElemVisited)
 
static xmlNsPtr xsltShallowCopyNsNode (xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr insert, xmlNsPtr ns)
 
static int xsltApplyFallbacks (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst)
 
static void xsltDefaultProcessOneNode (xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStackElemPtr params)
 
void xsltProcessOneNode (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xsltStackElemPtr withParams)
 
int xsltLocalVariablePush (xsltTransformContextPtr ctxt, xsltStackElemPtr variable, int level)
 
static void xsltReleaseLocalRVTs (xsltTransformContextPtr ctxt, xmlDocPtr base)
 
void xsltApplyOneTemplate (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ ATTRIBUTE_UNUSED, xsltStackElemPtr params)
 
void xsltDocumentElem (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltSort (xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
void xsltCopy (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltText (xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
 
void xsltElement (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltComment (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
 
void xsltProcessingInstruction (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltCopyOf (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltValueOf (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltNumber (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltApplyImports (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
 
void xsltCallTemplate (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltApplyTemplates (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltChoose (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
 
void xsltIf (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltForEach (xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
 
void xsltApplyStripSpaces (xsltTransformContextPtr ctxt, xmlNodePtr node)
 
static int xsltCountKeys (xsltTransformContextPtr ctxt)
 
static xmlDocPtr xsltApplyStylesheetInternal (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
 
xmlDocPtr xsltApplyStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params)
 
xmlDocPtr xsltProfileStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, FILE *output)
 
xmlDocPtr xsltApplyStylesheetUser (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
 
int xsltRunStylesheetUser (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf, FILE *profile, xsltTransformContextPtr userCtxt)
 
int xsltRunStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf)
 
static void xsltMessageWrapper (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
 
void xsltRegisterAllElement (xsltTransformContextPtr ctxt)
 

Variables

int xsltMaxDepth = 3000
 
int xsltMaxVars = 15000
 
static int xsltDoXIncludeDefault = 0
 
static unsigned long xsltDefaultTrace = (unsigned long) XSLT_TRACE_ALL
 
static xsltHTMLVersion xsltHTMLVersions []
 

Macro Definition Documentation

◆ FALSE

#define FALSE   (0 == 1)

Definition at line 43 of file transform.c.

◆ IS_BLANK_NODE

#define IS_BLANK_NODE (   n)    (((n)->type == XML_TEXT_NODE) && (xsltIsBlank((n)->content)))

Definition at line 47 of file transform.c.

◆ TRUE

#define TRUE   (!FALSE)

Definition at line 44 of file transform.c.

◆ XSLT_GENERATE_HTML_DOCTYPE

#define XSLT_GENERATE_HTML_DOCTYPE

Definition at line 29 of file transform.c.

Typedef Documentation

◆ xsltHTMLVersion

Function Documentation

◆ templPop()

static xsltTemplatePtr templPop ( xsltTransformContextPtr  ctxt)
static

templPop: @ctxt: the transformation context

Pop a template value from the stack

Returns the stored template value

Definition at line 121 of file transform.c.

122 {
124 
125  if (ctxt->templNr <= 0)
126  return (0);
127  ctxt->templNr--;
128  if (ctxt->templNr > 0)
129  ctxt->templ = ctxt->templTab[ctxt->templNr - 1];
130  else
131  ctxt->templ = (xsltTemplatePtr) 0;
132  ret = ctxt->templTab[ctxt->templNr];
133  ctxt->templTab[ctxt->templNr] = 0;
134  return (ret);
135 }
xsltTemplate * xsltTemplatePtr
xsltTemplatePtr * templTab
xsltTemplatePtr templ
int ret

Referenced by xsltApplyXSLTTemplate().

◆ templPush()

static int templPush ( xsltTransformContextPtr  ctxt,
xsltTemplatePtr  value 
)
static

templPush: @ctxt: the transformation context @value: the template to push on the stack

Push a template on the stack

Returns the new index in the stack or 0 in case of error

Definition at line 85 of file transform.c.

86 {
87  if (ctxt->templMax == 0) {
88  ctxt->templMax = 4;
89  ctxt->templTab =
91  sizeof(ctxt->templTab[0]));
92  if (ctxt->templTab == NULL) {
93  xmlGenericError(xmlGenericErrorContext, "malloc failed !\n");
94  return (0);
95  }
96  }
97  else if (ctxt->templNr >= ctxt->templMax) {
98  ctxt->templMax *= 2;
99  ctxt->templTab =
101  ctxt->templMax *
102  sizeof(ctxt->templTab[0]));
103  if (ctxt->templTab == NULL) {
104  xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
105  return (0);
106  }
107  }
108  ctxt->templTab[ctxt->templNr] = value;
109  ctxt->templ = value;
110  return (ctxt->templNr++);
111 }
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
xsltTemplatePtr * templTab
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:249
xsltTemplatePtr templ
GLsizei const GLfloat * value
Definition: glext.h:6069
#define NULL
Definition: types.h:112
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xsltApplyXSLTTemplate().

◆ xsltAddChild()

static xmlNodePtr xsltAddChild ( xmlNodePtr  parent,
xmlNodePtr  cur 
)
static

xsltAddChild: @parent: the parent node @cur: the child node

Wrapper version of xmlAddChild with a more consistent behaviour on error. One expect the use to be child = xsltAddChild(parent, child); and the routine will take care of not leaking on errors or node merge

Returns the child is successfully attached or NULL if merged or freed

Definition at line 752 of file transform.c.

752  {
753  xmlNodePtr ret;
754 
755  if (cur == NULL)
756  return(NULL);
757  if (parent == NULL) {
758  xmlFreeNode(cur);
759  return(NULL);
760  }
762 
763  return(ret);
764 }
XMLPUBFUN xmlNodePtr XMLCALL xmlAddChild(xmlNodePtr parent, xmlNodePtr cur)
r parent
Definition: btrfs.c:2944
Definition: tree.h:489
int ret
FxCollectionEntry * cur
#define NULL
Definition: types.h:112
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)

Referenced by xsltApplySequenceConstructor(), xsltComment(), xsltCopy(), xsltCopyText(), xsltCopyTextString(), xsltCopyTree(), xsltElement(), xsltProcessingInstruction(), xsltShallowCopyElem(), and xsltText().

◆ xsltAddTextString()

static xmlNodePtr xsltAddTextString ( xsltTransformContextPtr  ctxt,
xmlNodePtr  target,
const xmlChar string,
int  len 
)
static

xsltAddTextString: @ctxt: a XSLT process context @target: the text node where the text will be attached @string: the text string @len: the string length in byte

Extend the current text node with the new string, it handles coalescing

Returns: the text node

Definition at line 778 of file transform.c.

779  {
780  /*
781  * optimization
782  */
783  if ((len <= 0) || (string == NULL) || (target == NULL))
784  return(target);
785 
786  if (ctxt->lasttext == target->content) {
787  int minSize;
788 
789  /* Check for integer overflow accounting for NUL terminator. */
790  if (len >= INT_MAX - ctxt->lasttuse) {
792  "xsltCopyText: text allocation failed\n");
793  return(NULL);
794  }
795  minSize = ctxt->lasttuse + len + 1;
796 
797  if (ctxt->lasttsize < minSize) {
798  xmlChar *newbuf;
799  int size;
800  int extra;
801 
802  /* Double buffer size but increase by at least 100 bytes. */
803  extra = minSize < 100 ? 100 : minSize;
804 
805  /* Check for integer overflow. */
806  if (extra > INT_MAX - ctxt->lasttsize) {
807  size = INT_MAX;
808  }
809  else {
810  size = ctxt->lasttsize + extra;
811  }
812 
813  newbuf = (xmlChar *) xmlRealloc(target->content,size);
814  if (newbuf == NULL) {
816  "xsltCopyText: text allocation failed\n");
817  return(NULL);
818  }
819  ctxt->lasttsize = size;
820  ctxt->lasttext = newbuf;
821  target->content = newbuf;
822  }
823  memcpy(&(target->content[ctxt->lasttuse]), string, len);
824  ctxt->lasttuse += len;
825  target->content[ctxt->lasttuse] = 0;
826  } else {
827  xmlNodeAddContent(target, string);
828  ctxt->lasttext = target->content;
829  len = xmlStrlen(target->content);
830  ctxt->lasttsize = len;
831  ctxt->lasttuse = len;
832  }
833  return(target);
834 }
XMLPUBFUN void XMLCALL xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content)
#define INT_MAX
Definition: limits.h:40
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:249
GLsizeiptr size
Definition: glext.h:5919
Definition: id3.c:95
const xmlChar * lasttext
unsigned char xmlChar
Definition: xmlstring.h:28
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define NULL
Definition: types.h:112
GLenum target
Definition: glext.h:7315
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678

Referenced by xsltCopyText(), and xsltCopyTextString().

◆ xsltApplyFallbacks()

static int xsltApplyFallbacks ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst 
)
static

xsltApplyFallbacks: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the node generating the error

Process possible xsl:fallback nodes present under @inst

Returns the number of xsl:fallback element found and processed

Definition at line 1804 of file transform.c.

1805  {
1806 
1807  xmlNodePtr child;
1808  int ret = 0;
1809 
1810  if ((ctxt == NULL) || (node == NULL) || (inst == NULL) ||
1811  (inst->children == NULL))
1812  return(0);
1813 
1814  child = inst->children;
1815  while (child != NULL) {
1816  if ((IS_XSLT_ELEM(child)) &&
1817  (xmlStrEqual(child->name, BAD_CAST "fallback"))) {
1818 #ifdef WITH_XSLT_DEBUG_PARSING
1820  "applying xsl:fallback\n");
1821 #endif
1822  ret++;
1823  xsltApplySequenceConstructor(ctxt, node, child->children,
1824  NULL);
1825  }
1826  child = child->next;
1827  }
1828  return(ret);
1829 }
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
static HWND child
Definition: cursoricon.c:298
#define BAD_CAST
Definition: xmlstring.h:35
void * xsltGenericDebugContext
Definition: xsltutils.c:549
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
int ret
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
#define NULL
Definition: types.h:112
struct _xmlNode * children
Definition: tree.h:493
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
Definition: dlist.c:348

Referenced by xsltApplySequenceConstructor().

◆ xsltApplyImports()

void xsltApplyImports ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst,
xsltElemPreCompPtr comp  ATTRIBUTE_UNUSED 
)

xsltApplyImports: @ctxt: an XSLT transformation context @contextNode: the current node in the source tree. @inst: the element node of the XSLT 'apply-imports' instruction @comp: the compiled instruction

Process the XSLT apply-imports element.

Definition at line 4650 of file transform.c.

4653 {
4654  xsltTemplatePtr templ;
4655 
4656  if ((ctxt == NULL) || (inst == NULL))
4657  return;
4658 
4659  if (comp == NULL) {
4660  xsltTransformError(ctxt, NULL, inst,
4661  "Internal error in xsltApplyImports(): "
4662  "The XSLT 'apply-imports' instruction was not compiled.\n");
4663  return;
4664  }
4665  /*
4666  * NOTE that ctxt->currentTemplateRule and ctxt->templ is not the
4667  * same; the former is the "Current Template Rule" as defined by the
4668  * XSLT spec, the latter is simply the template struct being
4669  * currently processed.
4670  */
4671  if (ctxt->currentTemplateRule == NULL) {
4672  /*
4673  * SPEC XSLT 2.0:
4674  * "[ERR XTDE0560] It is a non-recoverable dynamic error if
4675  * xsl:apply-imports or xsl:next-match is evaluated when the
4676  * current template rule is null."
4677  */
4678  xsltTransformError(ctxt, NULL, inst,
4679  "It is an error to call 'apply-imports' "
4680  "when there's no current template rule.\n");
4681  return;
4682  }
4683  /*
4684  * TODO: Check if this is correct.
4685  */
4686  templ = xsltGetTemplate(ctxt, contextNode,
4687  ctxt->currentTemplateRule->style);
4688 
4689  if (templ != NULL) {
4690  xsltTemplatePtr oldCurTemplRule = ctxt->currentTemplateRule;
4691  /*
4692  * Set the current template rule.
4693  */
4694  ctxt->currentTemplateRule = templ;
4695  /*
4696  * URGENT TODO: Need xsl:with-param be handled somehow here?
4697  */
4698  xsltApplyXSLTTemplate(ctxt, contextNode, templ->content,
4699  templ, NULL);
4700 
4701  ctxt->currentTemplateRule = oldCurTemplRule;
4702  }
4703  else {
4704  /* Use built-in templates. */
4705  xsltDefaultProcessOneNode(ctxt, contextNode, NULL);
4706  }
4707 }
xmlNodePtr content
static void xsltApplyXSLTTemplate(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ, xsltStackElemPtr withParams)
Definition: transform.c:3068
xsltTemplatePtr xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylesheetPtr style)
Definition: pattern.c:2344
static void xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStackElemPtr params)
Definition: transform.c:1860
xsltTemplatePtr currentTemplateRule
struct _xsltStylesheet * style
#define NULL
Definition: types.h:112
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltApplyOneTemplate()

void xsltApplyOneTemplate ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  list,
xsltTemplatePtr templ  ATTRIBUTE_UNUSED,
xsltStackElemPtr  params 
)

xsltApplyOneTemplate: @ctxt: a XSLT process context @contextNode: the node in the source tree. @list: the nodes of a sequence constructor @templ: not used @params: a set of parameters (xsl:param) or NULL

Processes a sequence constructor on the current node in the source tree.

@params are the already computed variable stack items; this function pushes them on the variable stack, and pops them before exiting; it's left to the caller to free or reuse @params afterwards. The initial states of the variable stack will always be restored before this function exits. NOTE that this does not initiate a new distinct variable scope; i.e. variables already on the stack are visible to the process. The caller's side needs to start a new variable scope if needed (e.g. in exsl:function).

@templ is obsolete and not used anymore (e.g. <exslt:function> does not provide a @templ); a non-NULL @templ might raise an error in the future.

BIG NOTE: This function is not intended to process the content of an xsl:template; it does not expect xsl:param instructions in @list and will report errors if found.

Called by:

Definition at line 3315 of file transform.c.

3320 {
3321  if ((ctxt == NULL) || (list == NULL))
3322  return;
3323  CHECK_STOPPED;
3324 
3325  if (params) {
3326  /*
3327  * This code should be obsolete - was previously used
3328  * by libexslt/functions.c, but due to bug 381319 the
3329  * logic there was changed.
3330  */
3331  int oldVarsNr = ctxt->varsNr;
3332 
3333  /*
3334  * Push the given xsl:param(s) onto the variable stack.
3335  */
3336  while (params != NULL) {
3337  xsltLocalVariablePush(ctxt, params, -1);
3338  params = params->next;
3339  }
3340  xsltApplySequenceConstructor(ctxt, contextNode, list, templ);
3341  /*
3342  * Pop the given xsl:param(s) from the stack but don't free them.
3343  */
3344  xsltLocalVariablePop(ctxt, oldVarsNr, -2);
3345  } else
3346  xsltApplySequenceConstructor(ctxt, contextNode, list, templ);
3347 }
#define CHECK_STOPPED
GLenum const GLfloat * params
Definition: glext.h:5645
int xsltLocalVariablePush(xsltTransformContextPtr ctxt, xsltStackElemPtr variable, int level)
Definition: transform.c:2230
Definition: _list.h:228
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
#define NULL
Definition: types.h:112
void xsltLocalVariablePop(xsltTransformContextPtr ctxt, int limitNr, int level)
Definition: transform.c:150

Referenced by xsltEvalGlobalVariable(), xsltEvalTemplateString(), and xsltEvalVariable().

◆ xsltApplySequenceConstructor()

static void xsltApplySequenceConstructor ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  list,
xsltTemplatePtr  templ 
)
static

xsltApplySequenceConstructor: @ctxt: a XSLT process context @contextNode: the "current node" in the source tree @list: the nodes of a sequence constructor; (plus leading xsl:param elements) @templ: the compiled xsl:template (optional)

Processes a sequence constructor.

NOTE: ctxt->currentTemplateRule was introduced to reflect the semantics of "current template rule". I.e. the field ctxt->templ is not intended to reflect this, thus always pushed onto the template stack.

Definition at line 2320 of file transform.c.

2323 {
2324  xmlNodePtr oldInsert, oldInst, oldCurInst, oldContextNode;
2326  int level = 0, oldVarsNr;
2327  xmlDocPtr oldLocalFragmentTop;
2328 
2329 #ifdef XSLT_REFACTORED
2331 #endif
2332 
2333 #ifdef WITH_DEBUGGER
2334  int addCallResult = 0;
2335  xmlNodePtr debuggedNode = NULL;
2336 #endif
2337 
2338  if (ctxt == NULL)
2339  return;
2340 
2341 #ifdef WITH_DEBUGGER
2342  if (ctxt->debugStatus != XSLT_DEBUG_NONE) {
2343  debuggedNode =
2344  xsltDebuggerStartSequenceConstructor(ctxt, contextNode,
2345  list, templ, &addCallResult);
2346  if (debuggedNode == NULL)
2347  return;
2348  }
2349 #endif
2350 
2351  if (list == NULL)
2352  return;
2353  CHECK_STOPPED;
2354 
2355  /*
2356  * Check for infinite recursion: stop if the maximum of nested templates
2357  * is excceeded. Adjust xsltMaxDepth if you need more.
2358  */
2359  if (ctxt->depth >= ctxt->maxTemplateDepth) {
2360  xsltTransformError(ctxt, NULL, list,
2361  "xsltApplySequenceConstructor: A potential infinite template "
2362  "recursion was detected.\n"
2363  "You can adjust xsltMaxDepth (--maxdepth) in order to "
2364  "raise the maximum number of nested template calls and "
2365  "variables/params (currently set to %d).\n",
2366  ctxt->maxTemplateDepth);
2367  xsltDebug(ctxt, contextNode, list, NULL);
2368  ctxt->state = XSLT_STATE_STOPPED;
2369  return;
2370  }
2371  ctxt->depth++;
2372 
2373  oldLocalFragmentTop = ctxt->localRVT;
2374  oldInsert = insert = ctxt->insert;
2375  oldInst = oldCurInst = ctxt->inst;
2376  oldContextNode = ctxt->node;
2377  /*
2378  * Save current number of variables on the stack; new vars are popped when
2379  * exiting.
2380  */
2381  oldVarsNr = ctxt->varsNr;
2382  /*
2383  * Process the sequence constructor.
2384  */
2385  cur = list;
2386  while (cur != NULL) {
2387  if (ctxt->opLimit != 0) {
2388  if (ctxt->opCount >= ctxt->opLimit) {
2389  xsltTransformError(ctxt, NULL, cur,
2390  "xsltApplySequenceConstructor: "
2391  "Operation limit exceeded\n");
2392  ctxt->state = XSLT_STATE_STOPPED;
2393  goto error;
2394  }
2395  ctxt->opCount += 1;
2396  }
2397 
2398  ctxt->inst = cur;
2399 
2400 #ifdef WITH_DEBUGGER
2401  switch (ctxt->debugStatus) {
2403  case XSLT_DEBUG_QUIT:
2404  break;
2405 
2406  }
2407 #endif
2408  /*
2409  * Test; we must have a valid insertion point.
2410  */
2411  if (insert == NULL) {
2412 
2413 #ifdef WITH_XSLT_DEBUG_PROCESS
2415  "xsltApplySequenceConstructor: insert == NULL !\n"));
2416 #endif
2417  goto error;
2418  }
2419 
2420 #ifdef WITH_DEBUGGER
2421  if ((ctxt->debugStatus != XSLT_DEBUG_NONE) && (debuggedNode != cur))
2422  xslHandleDebugger(cur, contextNode, templ, ctxt);
2423 #endif
2424 
2425 #ifdef XSLT_REFACTORED
2426  if (cur->type == XML_ELEMENT_NODE) {
2427  info = (xsltStylePreCompPtr) cur->psvi;
2428  /*
2429  * We expect a compiled representation on:
2430  * 1) XSLT instructions of this XSLT version (1.0)
2431  * (with a few exceptions)
2432  * 2) Literal result elements
2433  * 3) Extension instructions
2434  * 4) XSLT instructions of future XSLT versions
2435  * (forwards-compatible mode).
2436  */
2437  if (info == NULL) {
2438  /*
2439  * Handle the rare cases where we don't expect a compiled
2440  * representation on an XSLT element.
2441  */
2442  if (IS_XSLT_ELEM_FAST(cur) && IS_XSLT_NAME(cur, "message")) {
2443  xsltMessage(ctxt, contextNode, cur);
2444  goto skip_children;
2445  }
2446  /*
2447  * Something really went wrong:
2448  */
2449  xsltTransformError(ctxt, NULL, cur,
2450  "Internal error in xsltApplySequenceConstructor(): "
2451  "The element '%s' in the stylesheet has no compiled "
2452  "representation.\n",
2453  cur->name);
2454  goto skip_children;
2455  }
2456 
2457  if (info->type == XSLT_FUNC_LITERAL_RESULT_ELEMENT) {
2458  xsltStyleItemLRElementInfoPtr lrInfo =
2459  (xsltStyleItemLRElementInfoPtr) info;
2460  /*
2461  * Literal result elements
2462  * --------------------------------------------------------
2463  */
2464 #ifdef WITH_XSLT_DEBUG_PROCESS
2467  "xsltApplySequenceConstructor: copy literal result "
2468  "element '%s'\n", cur->name));
2469 #endif
2470  /*
2471  * Copy the raw element-node.
2472  * OLD: if ((copy = xsltShallowCopyElem(ctxt, cur, insert))
2473  * == NULL)
2474  * goto error;
2475  */
2476  copy = xmlDocCopyNode(cur, insert->doc, 0);
2477  if (copy == NULL) {
2478  xsltTransformError(ctxt, NULL, cur,
2479  "Internal error in xsltApplySequenceConstructor(): "
2480  "Failed to copy literal result element '%s'.\n",
2481  cur->name);
2482  goto error;
2483  } else {
2484  /*
2485  * Add the element-node to the result tree.
2486  */
2487  copy->doc = ctxt->output;
2489  /*
2490  * Create effective namespaces declarations.
2491  * OLD: xsltCopyNamespaceList(ctxt, copy, cur->nsDef);
2492  */
2493  if (lrInfo->effectiveNs != NULL) {
2494  xsltEffectiveNsPtr effNs = lrInfo->effectiveNs;
2495  xmlNsPtr ns, lastns = NULL;
2496 
2497  while (effNs != NULL) {
2498  /*
2499  * Avoid generating redundant namespace
2500  * declarations; thus lookup if there is already
2501  * such a ns-decl in the result.
2502  */
2503  ns = xmlSearchNs(copy->doc, copy, effNs->prefix);
2504  if ((ns != NULL) &&
2505  (xmlStrEqual(ns->href, effNs->nsName)))
2506  {
2507  effNs = effNs->next;
2508  continue;
2509  }
2510  ns = xmlNewNs(copy, effNs->nsName, effNs->prefix);
2511  if (ns == NULL) {
2512  xsltTransformError(ctxt, NULL, cur,
2513  "Internal error in "
2514  "xsltApplySequenceConstructor(): "
2515  "Failed to copy a namespace "
2516  "declaration.\n");
2517  goto error;
2518  }
2519 
2520  if (lastns == NULL)
2521  copy->nsDef = ns;
2522  else
2523  lastns->next =ns;
2524  lastns = ns;
2525 
2526  effNs = effNs->next;
2527  }
2528 
2529  }
2530  /*
2531  * NOTE that we don't need to apply ns-alising: this was
2532  * already done at compile-time.
2533  */
2534  if (cur->ns != NULL) {
2535  /*
2536  * If there's no such ns-decl in the result tree,
2537  * then xsltGetSpecialNamespace() will
2538  * create a ns-decl on the copied node.
2539  */
2540  copy->ns = xsltGetSpecialNamespace(ctxt, cur,
2541  cur->ns->href, cur->ns->prefix, copy);
2542  } else {
2543  /*
2544  * Undeclare the default namespace if needed.
2545  * This can be skipped, if the result element has
2546  * no ns-decls, in which case the result element
2547  * obviously does not declare a default namespace;
2548  * AND there's either no parent, or the parent
2549  * element is in no namespace; this means there's no
2550  * default namespace is scope to care about.
2551  *
2552  * REVISIT: This might result in massive
2553  * generation of ns-decls if nodes in a default
2554  * namespaces are mixed with nodes in no namespace.
2555  *
2556  */
2557  if (copy->nsDef ||
2558  ((insert != NULL) &&
2559  (insert->type == XML_ELEMENT_NODE) &&
2560  (insert->ns != NULL)))
2561  {
2563  NULL, NULL, copy);
2564  }
2565  }
2566  }
2567  /*
2568  * SPEC XSLT 2.0 "Each attribute of the literal result
2569  * element, other than an attribute in the XSLT namespace,
2570  * is processed to produce an attribute for the element in
2571  * the result tree."
2572  * NOTE: See bug #341325.
2573  */
2574  if (cur->properties != NULL) {
2575  xsltAttrListTemplateProcess(ctxt, copy, cur->properties);
2576  }
2577  } else if (IS_XSLT_ELEM_FAST(cur)) {
2578  /*
2579  * XSLT instructions
2580  * --------------------------------------------------------
2581  */
2582  if (info->type == XSLT_FUNC_UNKOWN_FORWARDS_COMPAT) {
2583  /*
2584  * We hit an unknown XSLT element.
2585  * Try to apply one of the fallback cases.
2586  */
2587  ctxt->insert = insert;
2588  if (!xsltApplyFallbacks(ctxt, contextNode, cur)) {
2589  xsltTransformError(ctxt, NULL, cur,
2590  "The is no fallback behaviour defined for "
2591  "the unknown XSLT element '%s'.\n",
2592  cur->name);
2593  }
2594  ctxt->insert = oldInsert;
2595  } else if (info->func != NULL) {
2596  /*
2597  * Execute the XSLT instruction.
2598  */
2599  ctxt->insert = insert;
2600 
2601  info->func(ctxt, contextNode, cur,
2603 
2604  /*
2605  * Cleanup temporary tree fragments.
2606  */
2607  if (oldLocalFragmentTop != ctxt->localRVT)
2608  xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop);
2609 
2610  ctxt->insert = oldInsert;
2611  } else if (info->type == XSLT_FUNC_VARIABLE) {
2612  xsltStackElemPtr tmpvar = ctxt->vars;
2613 
2615 
2616  if (tmpvar != ctxt->vars) {
2617  /*
2618  * TODO: Using a @tmpvar is an annoying workaround, but
2619  * the current mechanisms do not provide any other way
2620  * of knowing if the var was really pushed onto the
2621  * stack.
2622  */
2623  ctxt->vars->level = level;
2624  }
2625  } else if (info->type == XSLT_FUNC_MESSAGE) {
2626  /*
2627  * TODO: Won't be hit, since we don't compile xsl:message.
2628  */
2629  xsltMessage(ctxt, contextNode, cur);
2630  } else {
2631  xsltTransformError(ctxt, NULL, cur,
2632  "Unexpected XSLT element '%s'.\n", cur->name);
2633  }
2634  goto skip_children;
2635 
2636  } else {
2638  /*
2639  * Extension intructions (elements)
2640  * --------------------------------------------------------
2641  */
2642  if (cur->psvi == xsltExtMarker) {
2643  /*
2644  * The xsltExtMarker was set during the compilation
2645  * of extension instructions if there was no registered
2646  * handler for this specific extension function at
2647  * compile-time.
2648  * Libxslt will now lookup if a handler is
2649  * registered in the context of this transformation.
2650  */
2651  func = xsltExtElementLookup(ctxt, cur->name,
2652  cur->ns->href);
2653  } else
2654  func = ((xsltElemPreCompPtr) cur->psvi)->func;
2655 
2656  if (func == NULL) {
2657  /*
2658  * No handler available.
2659  * Try to execute fallback behaviour via xsl:fallback.
2660  */
2661 #ifdef WITH_XSLT_DEBUG_PROCESS
2664  "xsltApplySequenceConstructor: unknown extension %s\n",
2665  cur->name));
2666 #endif
2667  ctxt->insert = insert;
2668  if (!xsltApplyFallbacks(ctxt, contextNode, cur)) {
2669  xsltTransformError(ctxt, NULL, cur,
2670  "Unknown extension instruction '{%s}%s'.\n",
2671  cur->ns->href, cur->name);
2672  }
2673  ctxt->insert = oldInsert;
2674  } else {
2675  /*
2676  * Execute the handler-callback.
2677  */
2678 #ifdef WITH_XSLT_DEBUG_PROCESS
2680  "xsltApplySequenceConstructor: extension construct %s\n",
2681  cur->name));
2682 #endif
2683  /*
2684  * Disable the xsltCopyTextString optimization for
2685  * extension elements. Extensions could append text using
2686  * xmlAddChild which will free the buffer pointed to by
2687  * 'lasttext'. This buffer could later be reallocated with
2688  * a different size than recorded in 'lasttsize'. See bug
2689  * #777432.
2690  */
2691  if (cur->psvi == xsltExtMarker) {
2692  ctxt->lasttext = NULL;
2693  }
2694 
2695  ctxt->insert = insert;
2696 
2697  func(ctxt, contextNode, cur, cur->psvi);
2698 
2699  /*
2700  * Cleanup temporary tree fragments.
2701  */
2702  if (oldLocalFragmentTop != ctxt->localRVT)
2703  xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop);
2704 
2705  ctxt->insert = oldInsert;
2706  }
2707  goto skip_children;
2708  }
2709 
2710  } else if (XSLT_IS_TEXT_NODE(cur)) {
2711  /*
2712  * Text
2713  * ------------------------------------------------------------
2714  */
2715 #ifdef WITH_XSLT_DEBUG_PROCESS
2716  if (cur->name == xmlStringTextNoenc) {
2719  "xsltApplySequenceConstructor: copy unescaped text '%s'\n",
2720  cur->content));
2721  } else {
2724  "xsltApplySequenceConstructor: copy text '%s'\n",
2725  cur->content));
2726  }
2727 #endif
2728  if (xsltCopyText(ctxt, insert, cur, ctxt->internalized) == NULL)
2729  goto error;
2730  }
2731 
2732 #else /* XSLT_REFACTORED */
2733 
2734  if (IS_XSLT_ELEM(cur)) {
2735  /*
2736  * This is an XSLT node
2737  */
2739 
2740  if (info == NULL) {
2741  if (IS_XSLT_NAME(cur, "message")) {
2742  xsltMessage(ctxt, contextNode, cur);
2743  } else {
2744  /*
2745  * That's an error try to apply one of the fallback cases
2746  */
2747  ctxt->insert = insert;
2748  if (!xsltApplyFallbacks(ctxt, contextNode, cur)) {
2750  "xsltApplySequenceConstructor: %s was not compiled\n",
2751  cur->name);
2752  }
2753  ctxt->insert = oldInsert;
2754  }
2755  goto skip_children;
2756  }
2757 
2758  if (info->func != NULL) {
2759  oldCurInst = ctxt->inst;
2760  ctxt->inst = cur;
2761  ctxt->insert = insert;
2762 
2763  info->func(ctxt, contextNode, cur, (xsltElemPreCompPtr) info);
2764 
2765  /*
2766  * Cleanup temporary tree fragments.
2767  */
2768  if (oldLocalFragmentTop != ctxt->localRVT)
2769  xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop);
2770 
2771  ctxt->insert = oldInsert;
2772  ctxt->inst = oldCurInst;
2773  goto skip_children;
2774  }
2775 
2776  if (IS_XSLT_NAME(cur, "variable")) {
2777  xsltStackElemPtr tmpvar = ctxt->vars;
2778 
2779  oldCurInst = ctxt->inst;
2780  ctxt->inst = cur;
2781 
2783 
2784  ctxt->inst = oldCurInst;
2785 
2786  if (tmpvar != ctxt->vars) {
2787  /*
2788  * TODO: Using a @tmpvar is an annoying workaround, but
2789  * the current mechanisms do not provide any other way
2790  * of knowing if the var was really pushed onto the
2791  * stack.
2792  */
2793  ctxt->vars->level = level;
2794  }
2795  } else if (IS_XSLT_NAME(cur, "message")) {
2796  xsltMessage(ctxt, contextNode, cur);
2797  } else {
2798  xsltTransformError(ctxt, NULL, cur,
2799  "Unexpected XSLT element '%s'.\n", cur->name);
2800  }
2801  goto skip_children;
2802  } else if ((cur->type == XML_TEXT_NODE) ||
2803  (cur->type == XML_CDATA_SECTION_NODE)) {
2804 
2805  /*
2806  * This text comes from the stylesheet
2807  * For stylesheets, the set of whitespace-preserving
2808  * element names consists of just xsl:text.
2809  */
2810 #ifdef WITH_XSLT_DEBUG_PROCESS
2811  if (cur->type == XML_CDATA_SECTION_NODE) {
2813  "xsltApplySequenceConstructor: copy CDATA text %s\n",
2814  cur->content));
2815  } else if (cur->name == xmlStringTextNoenc) {
2817  "xsltApplySequenceConstructor: copy unescaped text %s\n",
2818  cur->content));
2819  } else {
2821  "xsltApplySequenceConstructor: copy text %s\n",
2822  cur->content));
2823  }
2824 #endif
2825  if (xsltCopyText(ctxt, insert, cur, ctxt->internalized) == NULL)
2826  goto error;
2827  } else if ((cur->type == XML_ELEMENT_NODE) &&
2828  (cur->ns != NULL) && (cur->psvi != NULL)) {
2829  xsltTransformFunction function;
2830 
2831  oldCurInst = ctxt->inst;
2832  ctxt->inst = cur;
2833  /*
2834  * Flagged as an extension element
2835  */
2836  if (cur->psvi == xsltExtMarker)
2837  function = xsltExtElementLookup(ctxt, cur->name,
2838  cur->ns->href);
2839  else
2840  function = ((xsltElemPreCompPtr) cur->psvi)->func;
2841 
2842  if (function == NULL) {
2843  xmlNodePtr child;
2844  int found = 0;
2845 
2846 #ifdef WITH_XSLT_DEBUG_PROCESS
2848  "xsltApplySequenceConstructor: unknown extension %s\n",
2849  cur->name));
2850 #endif
2851  /*
2852  * Search if there are fallbacks
2853  */
2854  ctxt->insert = insert;
2855  child = cur->children;
2856  while (child != NULL) {
2857  if ((IS_XSLT_ELEM(child)) &&
2858  (IS_XSLT_NAME(child, "fallback")))
2859  {
2860  found = 1;
2861  xsltApplySequenceConstructor(ctxt, contextNode,
2862  child->children, NULL);
2863  }
2864  child = child->next;
2865  }
2866  ctxt->insert = oldInsert;
2867 
2868  if (!found) {
2869  xsltTransformError(ctxt, NULL, cur,
2870  "xsltApplySequenceConstructor: failed to find extension %s\n",
2871  cur->name);
2872  }
2873  } else {
2874 #ifdef WITH_XSLT_DEBUG_PROCESS
2876  "xsltApplySequenceConstructor: extension construct %s\n",
2877  cur->name));
2878 #endif
2879 
2880  /*
2881  * Disable the xsltCopyTextString optimization for
2882  * extension elements. Extensions could append text using
2883  * xmlAddChild which will free the buffer pointed to by
2884  * 'lasttext'. This buffer could later be reallocated with
2885  * a different size than recorded in 'lasttsize'. See bug
2886  * #777432.
2887  */
2888  if (cur->psvi == xsltExtMarker) {
2889  ctxt->lasttext = NULL;
2890  }
2891 
2892  ctxt->insert = insert;
2893 
2894  function(ctxt, contextNode, cur, cur->psvi);
2895  /*
2896  * Cleanup temporary tree fragments.
2897  */
2898  if (oldLocalFragmentTop != ctxt->localRVT)
2899  xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop);
2900 
2901  ctxt->insert = oldInsert;
2902 
2903  }
2904  ctxt->inst = oldCurInst;
2905  goto skip_children;
2906  } else if (cur->type == XML_ELEMENT_NODE) {
2907 #ifdef WITH_XSLT_DEBUG_PROCESS
2909  "xsltApplySequenceConstructor: copy node %s\n",
2910  cur->name));
2911 #endif
2912  oldCurInst = ctxt->inst;
2913  ctxt->inst = cur;
2914 
2915  if ((copy = xsltShallowCopyElem(ctxt, cur, insert, 1)) == NULL)
2916  goto error;
2917  /*
2918  * Add extra namespaces inherited from the current template
2919  * if we are in the first level children and this is a
2920  * "real" template.
2921  */
2922  if ((templ != NULL) && (oldInsert == insert) &&
2923  (ctxt->templ != NULL) && (ctxt->templ->inheritedNs != NULL)) {
2924  int i;
2925  xmlNsPtr ns, ret;
2926 
2927  for (i = 0; i < ctxt->templ->inheritedNsNr; i++) {
2928  const xmlChar *URI = NULL;
2930  ns = ctxt->templ->inheritedNs[i];
2931 
2932  /* Note that the XSLT namespace was already excluded
2933  * in xsltGetInheritedNsList().
2934  */
2935 #if 0
2936  if (xmlStrEqual(ns->href, XSLT_NAMESPACE))
2937  continue;
2938 #endif
2939  style = ctxt->style;
2940  while (style != NULL) {
2941  if (style->nsAliases != NULL)
2942  URI = (const xmlChar *)
2943  xmlHashLookup(style->nsAliases, ns->href);
2944  if (URI != NULL)
2945  break;
2946 
2948  }
2949  if (URI == UNDEFINED_DEFAULT_NS)
2950  continue;
2951  if (URI == NULL)
2952  URI = ns->href;
2953  /*
2954  * TODO: The following will still be buggy for the
2955  * non-refactored code.
2956  */
2957  ret = xmlSearchNs(copy->doc, copy, ns->prefix);
2958  if ((ret == NULL) || (!xmlStrEqual(ret->href, URI)))
2959  {
2960  xmlNewNs(copy, URI, ns->prefix);
2961  }
2962  }
2963  if (copy->ns != NULL) {
2964  /*
2965  * Fix the node namespace if needed
2966  */
2967  copy->ns = xsltGetNamespace(ctxt, cur, copy->ns, copy);
2968  }
2969  }
2970  /*
2971  * all the attributes are directly inherited
2972  */
2973  if (cur->properties != NULL) {
2974  xsltAttrListTemplateProcess(ctxt, copy, cur->properties);
2975  }
2976  ctxt->inst = oldCurInst;
2977  }
2978 #endif /* else of XSLT_REFACTORED */
2979 
2980  /*
2981  * Descend into content in document order.
2982  */
2983  if (cur->children != NULL) {
2984  if (cur->children->type != XML_ENTITY_DECL) {
2985  cur = cur->children;
2986  level++;
2987  if (copy != NULL)
2988  insert = copy;
2989  continue;
2990  }
2991  }
2992 
2993 skip_children:
2994  /*
2995  * If xslt:message was just processed, we might have hit a
2996  * terminate='yes'; if so, then break the loop and clean up.
2997  * TODO: Do we need to check this also before trying to descend
2998  * into the content?
2999  */
3000  if (ctxt->state == XSLT_STATE_STOPPED)
3001  break;
3002  if (cur->next != NULL) {
3003  cur = cur->next;
3004  continue;
3005  }
3006 
3007  do {
3008  cur = cur->parent;
3009  level--;
3010  /*
3011  * Pop variables/params (xsl:variable and xsl:param).
3012  */
3013  if ((ctxt->varsNr > oldVarsNr) && (ctxt->vars->level > level)) {
3014  xsltLocalVariablePop(ctxt, oldVarsNr, level);
3015  }
3016 
3017  insert = insert->parent;
3018  if (cur == NULL)
3019  break;
3020  if (cur == list->parent) {
3021  cur = NULL;
3022  break;
3023  }
3024  if (cur->next != NULL) {
3025  cur = cur->next;
3026  break;
3027  }
3028  } while (cur != NULL);
3029  }
3030 
3031 error:
3032  /*
3033  * In case of errors: pop remaining variables.
3034  */
3035  if (ctxt->varsNr > oldVarsNr)
3036  xsltLocalVariablePop(ctxt, oldVarsNr, -1);
3037 
3038  ctxt->node = oldContextNode;
3039  ctxt->inst = oldInst;
3040  ctxt->insert = oldInsert;
3041 
3042  ctxt->depth--;
3043 
3044 #ifdef WITH_DEBUGGER
3045  if ((ctxt->debugStatus != XSLT_DEBUG_NONE) && (addCallResult)) {
3046  xslDropCall();
3047  }
3048 #endif
3049 }
GLenum func
Definition: glext.h:6028
void xsltMessage(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst)
Definition: xsltutils.c:408
GLint level
Definition: gl.h:1546
static int xsltApplyFallbacks(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst)
Definition: transform.c:1804
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:752
#define error(str)
Definition: mkdosfs.c:1605
void xsltParseStylesheetVariable(xsltTransformContextPtr ctxt, xmlNodePtr inst)
Definition: variables.c:2146
struct _xmlNs * next
Definition: tree.h:390
#define XSLT_IS_TEXT_NODE(n)
Definition: xsltInternals.h:38
void(* xsltTransformFunction)(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
Definition: tree.h:389
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:251
xmlNsPtr * inheritedNs
xmlNsPtr xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, xmlNodePtr out)
Definition: namespaces.c:596
xsltStackElemPtr vars
xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, const xmlChar *nsName, const xmlChar *nsPrefix, xmlNodePtr target)
Definition: namespaces.c:299
static int insert
Definition: xmllint.c:144
#define XSLT_NAMESPACE
Definition: xslt.h:46
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
static HWND child
Definition: cursoricon.c:298
static xmlNodePtr xsltCopyText(xsltTransformContextPtr ctxt, xmlNodePtr target, xmlNodePtr cur, int interned)
Definition: transform.c:946
#define CHECK_STOPPED
#define UNDEFINED_DEFAULT_NS
Definition: namespaces.h:30
XSLTPUBFUN void XSLTCALL xslHandleDebugger(xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
xmlGenericErrorFunc xsltGenericError
Definition: xsltutils.c:502
XSLTPUBFUN void XSLTCALL xslDropCall(void)
xsltTransformState state
XMLPUBFUN xmlNsPtr XMLCALL xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace)
xsltTransformFunction xsltExtElementLookup(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *URI)
Definition: extensions.c:1668
void * xsltGenericDebugContext
Definition: xsltutils.c:549
if(!(yy_init))
Definition: macro.lex.yy.c:714
xsltTemplatePtr templ
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
void * xsltGenericErrorContext
Definition: xsltutils.c:503
struct _test_info info[]
Definition: SetCursorPos.c:19
Definition: tree.h:489
int ret
Definition: mxnamespace.c:44
const xmlChar * lasttext
xmlAttrPtr xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target, xmlAttrPtr attrs)
Definition: templates.c:627
unsigned char xmlChar
Definition: xmlstring.h:28
Definition: _list.h:228
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
BSTR prefix
Definition: mxnamespace.c:46
XMLPUBFUN xmlNsPtr XMLCALL xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix)
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
xsltElemPreComp * xsltElemPreCompPtr
FxCollectionEntry * cur
xsltStylePreComp * xsltStylePreCompPtr
xsltStylesheetPtr style
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
static xmlNodePtr xsltShallowCopyElem(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr insert, int isLRE)
Definition: transform.c:1297
#define list
Definition: rosglue.h:35
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
XMLPUBVAR const xmlChar xmlStringTextNoenc[]
#define NULL
Definition: types.h:112
Definition: tree.h:551
void xsltLocalVariablePop(xsltTransformContextPtr ctxt, int limitNr, int level)
Definition: transform.c:150
XMLPUBFUN xmlNodePtr XMLCALL xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int recursive)
XMLPUBFUN void *XMLCALL xmlHashLookup(xmlHashTablePtr table, const xmlChar *name)
Definition: hash.c:466
void xsltDebug(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst ATTRIBUTE_UNUSED, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: extra.c:35
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
Arabic default style
Definition: afstyles.h:93
#define IS_XSLT_NAME(n, val)
Definition: xsltutils.h:63
static void xsltReleaseLocalRVTs(xsltTransformContextPtr ctxt, xmlDocPtr base)
Definition: transform.c:2268
const xmlChar * xsltExtMarker
Definition: preproc.c:24

Referenced by xsltApplyFallbacks(), xsltApplyOneTemplate(), xsltApplyXSLTTemplate(), xsltChoose(), xsltCopy(), xsltDocumentElem(), xsltElement(), xsltForEach(), and xsltIf().

◆ xsltApplyStripSpaces()

void xsltApplyStripSpaces ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node 
)

xsltApplyStripSpaces: @ctxt: a XSLT process context @node: the root of the XML tree

Strip the unwanted ignorable spaces from the input tree

Definition at line 5712 of file transform.c.

5712  {
5714 #ifdef WITH_XSLT_DEBUG_PROCESS
5715  int nb = 0;
5716 #endif
5717 
5718 
5719  current = node;
5720  while (current != NULL) {
5721  /*
5722  * Cleanup children empty nodes if asked for
5723  */
5724  if ((IS_XSLT_REAL_NODE(current)) &&
5725  (current->children != NULL) &&
5727  xmlNodePtr delete = NULL, cur = current->children;
5728 
5729  while (cur != NULL) {
5730  if (IS_BLANK_NODE(cur))
5731  delete = cur;
5732 
5733  cur = cur->next;
5734  if (delete != NULL) {
5735  xmlUnlinkNode(delete);
5736  xmlFreeNode(delete);
5737  delete = NULL;
5738 #ifdef WITH_XSLT_DEBUG_PROCESS
5739  nb++;
5740 #endif
5741  }
5742  }
5743  }
5744 
5745  /*
5746  * Skip to next node in document order.
5747  */
5748  if (node->type == XML_ENTITY_REF_NODE) {
5749  /* process deep in entities */
5750  xsltApplyStripSpaces(ctxt, node->children);
5751  }
5752  if ((current->children != NULL) &&
5753  (current->type != XML_ENTITY_REF_NODE)) {
5754  current = current->children;
5755  } else if (current->next != NULL) {
5756  current = current->next;
5757  } else {
5758  do {
5759  current = current->parent;
5760  if (current == NULL)
5761  break;
5762  if (current == node)
5763  goto done;
5764  if (current->next != NULL) {
5765  current = current->next;
5766  break;
5767  }
5768  } while (current != NULL);
5769  }
5770  }
5771 
5772 done:
5773 #ifdef WITH_XSLT_DEBUG_PROCESS
5775  "xsltApplyStripSpaces: removed %d ignorable blank node\n", nb));
5776 #endif
5777  return;
5778 }
struct node node
#define IS_BLANK_NODE(n)
Definition: transform.c:47
void * xsltGenericDebugContext
Definition: xsltutils.c:549
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
#define IS_XSLT_REAL_NODE(n)
Definition: xsltutils.h:71
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
int xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: imports.c:303
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
FxCollectionEntry * cur
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5712
#define NULL
Definition: types.h:112
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
struct task_struct * current
Definition: linux.c:32
Definition: dlist.c:348

Referenced by xsltApplyStripSpaces(), xsltApplyStylesheetInternal(), and xsltLoadDocument().

◆ xsltApplyStylesheet()

xmlDocPtr xsltApplyStylesheet ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params 
)

xsltApplyStylesheet: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated arry of parameters names/values tuples

Apply the stylesheet to the document NOTE: This may lead to a non-wellformed output XML wise !

Returns the result document or NULL in case of error

Definition at line 6247 of file transform.c.

6249 {
6251 }
static xmlDocPtr xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
Definition: transform.c:5832
GLenum const GLfloat * params
Definition: glext.h:5645
#define NULL
Definition: types.h:112
Arabic default style
Definition: afstyles.h:93

◆ xsltApplyStylesheetInternal()

static xmlDocPtr xsltApplyStylesheetInternal ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params,
const char output,
FILE profile,
xsltTransformContextPtr  userCtxt 
)
static

xsltApplyStylesheetInternal: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated array of parameters names/values tuples @output: the targetted output @profile: profile FILE * output or NULL @user: user provided parameter

Apply the stylesheet to the document NOTE: This may lead to a non-wellformed output XML wise !

Returns the result document or NULL in case of error

Definition at line 5832 of file transform.c.

5835 {
5836  xmlDocPtr res = NULL;
5838  xmlNodePtr root, node;
5839  const xmlChar *method;
5840  const xmlChar *doctypePublic;
5841  const xmlChar *doctypeSystem;
5842  const xmlChar *version;
5843  const xmlChar *encoding;
5844  xsltStackElemPtr variables;
5845  xsltStackElemPtr vptr;
5846 
5847  xsltInitGlobals();
5848 
5849  if ((style == NULL) || (doc == NULL))
5850  return (NULL);
5851 
5852  if (style->internalized == 0) {
5853 #ifdef WITH_XSLT_DEBUG
5855  "Stylesheet was not fully internalized !\n");
5856 #endif
5857  }
5858  if (doc->intSubset != NULL) {
5859  /*
5860  * Avoid hitting the DTD when scanning nodes
5861  * but keep it linked as doc->intSubset
5862  */
5864  if (cur->next != NULL)
5865  cur->next->prev = cur->prev;
5866  if (cur->prev != NULL)
5867  cur->prev->next = cur->next;
5868  if (doc->children == cur)
5869  doc->children = cur->next;
5870  if (doc->last == cur)
5871  doc->last = cur->prev;
5872  cur->prev = cur->next = NULL;
5873  }
5874 
5875  /*
5876  * Check for XPath document order availability
5877  */
5878  root = xmlDocGetRootElement(doc);
5879  if (root != NULL) {
5880  if (((ptrdiff_t) root->content >= 0) &&
5882  xmlXPathOrderDocElems(doc);
5883  }
5884 
5885  if (userCtxt != NULL)
5886  ctxt = userCtxt;
5887  else
5888  ctxt = xsltNewTransformContext(style, doc);
5889 
5890  if (ctxt == NULL)
5891  return (NULL);
5892 
5893  ctxt->initialContextDoc = doc;
5894  ctxt->initialContextNode = (xmlNodePtr) doc;
5895 
5896  if (profile != NULL) {
5897 #ifdef WITH_PROFILER
5898  ctxt->profile = 1;
5899 #else
5900  xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
5901  "xsltApplyStylesheetInternal: "
5902  "libxslt compiled without profiler\n");
5903  goto error;
5904 #endif
5905  }
5906 
5907  if (output != NULL)
5908  ctxt->outputFile = output;
5909  else
5910  ctxt->outputFile = NULL;
5911 
5912  /*
5913  * internalize the modes if needed
5914  */
5915  if (ctxt->dict != NULL) {
5916  if (ctxt->mode != NULL)
5917  ctxt->mode = xmlDictLookup(ctxt->dict, ctxt->mode, -1);
5918  if (ctxt->modeURI != NULL)
5919  ctxt->modeURI = xmlDictLookup(ctxt->dict, ctxt->modeURI, -1);
5920  }
5921 
5923  XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
5924  XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
5927 
5928  if ((method != NULL) &&
5929  (!xmlStrEqual(method, (const xmlChar *) "xml")))
5930  {
5931  if (xmlStrEqual(method, (const xmlChar *) "html")) {
5932  ctxt->type = XSLT_OUTPUT_HTML;
5933  if (((doctypePublic != NULL) || (doctypeSystem != NULL))) {
5934  res = htmlNewDoc(doctypeSystem, doctypePublic);
5935  } else {
5936  if (version == NULL) {
5937  xmlDtdPtr dtd;
5938 
5939  res = htmlNewDoc(NULL, NULL);
5940  /*
5941  * Make sure no DTD node is generated in this case
5942  */
5943  if (res != NULL) {
5944  dtd = xmlGetIntSubset(res);
5945  if (dtd != NULL) {
5946  xmlUnlinkNode((xmlNodePtr) dtd);
5947  xmlFreeDtd(dtd);
5948  }
5949  res->intSubset = NULL;
5950  res->extSubset = NULL;
5951  }
5952  } else {
5953 
5954 #ifdef XSLT_GENERATE_HTML_DOCTYPE
5955  xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem);
5956 #endif
5957  res = htmlNewDoc(doctypeSystem, doctypePublic);
5958  }
5959  }
5960  if (res == NULL)
5961  goto error;
5962  res->dict = ctxt->dict;
5963  xmlDictReference(res->dict);
5964 
5965 #ifdef WITH_XSLT_DEBUG
5967  "reusing transformation dict for output\n");
5968 #endif
5969  } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) {
5970  xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
5971  "xsltApplyStylesheetInternal: unsupported method xhtml, using html\n");
5972  ctxt->type = XSLT_OUTPUT_HTML;
5973  res = htmlNewDoc(doctypeSystem, doctypePublic);
5974  if (res == NULL)
5975  goto error;
5976  res->dict = ctxt->dict;
5977  xmlDictReference(res->dict);
5978 
5979 #ifdef WITH_XSLT_DEBUG
5981  "reusing transformation dict for output\n");
5982 #endif
5983  } else if (xmlStrEqual(method, (const xmlChar *) "text")) {
5984  ctxt->type = XSLT_OUTPUT_TEXT;
5985  res = xmlNewDoc(style->version);
5986  if (res == NULL)
5987  goto error;
5988  res->dict = ctxt->dict;
5989  xmlDictReference(res->dict);
5990 
5991 #ifdef WITH_XSLT_DEBUG
5993  "reusing transformation dict for output\n");
5994 #endif
5995  } else {
5996  xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
5997  "xsltApplyStylesheetInternal: unsupported method (%s)\n",
5998  method);
5999  goto error;
6000  }
6001  } else {
6002  ctxt->type = XSLT_OUTPUT_XML;
6003  res = xmlNewDoc(style->version);
6004  if (res == NULL)
6005  goto error;
6006  res->dict = ctxt->dict;
6007  xmlDictReference(ctxt->dict);
6008 #ifdef WITH_XSLT_DEBUG
6010  "reusing transformation dict for output\n");
6011 #endif
6012  }
6013  res->charset = XML_CHAR_ENCODING_UTF8;
6014  if (encoding != NULL)
6015  res->encoding = xmlStrdup(encoding);
6016  variables = style->variables;
6017 
6018  ctxt->node = (xmlNodePtr) doc;
6019  ctxt->output = res;
6020 
6021  ctxt->xpathCtxt->contextSize = 1;
6022  ctxt->xpathCtxt->proximityPosition = 1;
6023  ctxt->xpathCtxt->node = NULL; /* TODO: Set the context node here? */
6024 
6025  /*
6026  * Start the evaluation, evaluate the params, the stylesheets globals
6027  * and start by processing the top node.
6028  */
6029  if (xsltNeedElemSpaceHandling(ctxt))
6031  /*
6032  * Evaluate global params and user-provided params.
6033  */
6034  if (ctxt->globalVars == NULL)
6035  ctxt->globalVars = xmlHashCreate(20);
6036  if (params != NULL) {
6037  xsltEvalUserParams(ctxt, params);
6038  }
6039 
6040  /* need to be called before evaluating global variables */
6041  xsltCountKeys(ctxt);
6042 
6044 
6045  /* Clean up any unused RVTs. */
6046  xsltReleaseLocalRVTs(ctxt, NULL);
6047 
6048  ctxt->insert = (xmlNodePtr) res;
6049  ctxt->varsBase = ctxt->varsNr - 1;
6050 
6051  /*
6052  * Start processing the source tree -----------------------------------
6053  */
6054  xsltProcessOneNode(ctxt, ctxt->node, NULL);
6055  /*
6056  * Remove all remaining vars from the stack.
6057  */
6058  xsltLocalVariablePop(ctxt, 0, -2);
6059  xsltShutdownCtxtExts(ctxt);
6060 
6061  xsltCleanupTemplates(style); /* TODO: <- style should be read only */
6062 
6063  /*
6064  * Now cleanup our variables so stylesheet can be re-used
6065  *
6066  * TODO: this is not needed anymore global variables are copied
6067  * and not evaluated directly anymore, keep this as a check
6068  */
6069  if (style->variables != variables) {
6070  vptr = style->variables;
6071  while (vptr->next != variables)
6072  vptr = vptr->next;
6073  vptr->next = NULL;
6074  xsltFreeStackElemList(style->variables);
6075  style->variables = variables;
6076  }
6077  vptr = style->variables;
6078  while (vptr != NULL) {
6079  if (vptr->computed) {
6080  if (vptr->value != NULL) {
6081  xmlXPathFreeObject(vptr->value);
6082  vptr->value = NULL;
6083  vptr->computed = 0;
6084  }
6085  }
6086  vptr = vptr->next;
6087  }
6088 #if 0
6089  /*
6090  * code disabled by wmb; awaiting kb's review
6091  * problem is that global variable(s) may contain xpath objects
6092  * from doc associated with RVT, so can't be freed at this point.
6093  * xsltFreeTransformContext includes a call to xsltFreeRVTs, so
6094  * I assume this shouldn't be required at this point.
6095  */
6096  /*
6097  * Free all remaining tree fragments.
6098  */
6099  xsltFreeRVTs(ctxt);
6100 #endif
6101  /*
6102  * Do some post processing work depending on the generated output
6103  */
6105  if (root != NULL) {
6106  const xmlChar *doctype = NULL;
6107 
6108  if ((root->ns != NULL) && (root->ns->prefix != NULL))
6109  doctype = xmlDictQLookup(ctxt->dict, root->ns->prefix, root->name);
6110  if (doctype == NULL)
6111  doctype = root->name;
6112 
6113  /*
6114  * Apply the default selection of the method
6115  */
6116  if ((method == NULL) &&
6117  (root->ns == NULL) &&
6118  (!xmlStrcasecmp(root->name, (const xmlChar *) "html"))) {
6119  xmlNodePtr tmp;
6120 
6121  tmp = res->children;
6122  while ((tmp != NULL) && (tmp != root)) {
6123  if (tmp->type == XML_ELEMENT_NODE)
6124  break;
6125  if ((tmp->type == XML_TEXT_NODE) && (!xmlIsBlankNode(tmp)))
6126  break;
6127  tmp = tmp->next;
6128  }
6129  if (tmp == root) {
6130  ctxt->type = XSLT_OUTPUT_HTML;
6131  /*
6132  * REVISIT TODO: XML_HTML_DOCUMENT_NODE is set after the
6133  * transformation on the doc, but functions like
6134  */
6135  res->type = XML_HTML_DOCUMENT_NODE;
6136  if (((doctypePublic != NULL) || (doctypeSystem != NULL))) {
6137  res->intSubset = xmlCreateIntSubset(res, doctype,
6138  doctypePublic,
6139  doctypeSystem);
6140 #ifdef XSLT_GENERATE_HTML_DOCTYPE
6141  } else if (version != NULL) {
6142  xsltGetHTMLIDs(version, &doctypePublic,
6143  &doctypeSystem);
6144  if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
6145  res->intSubset =
6146  xmlCreateIntSubset(res, doctype,
6147  doctypePublic,
6148  doctypeSystem);
6149 #endif
6150  }
6151  }
6152 
6153  }
6154  if (ctxt->type == XSLT_OUTPUT_XML) {
6155  XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
6156  XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
6157  if (((doctypePublic != NULL) || (doctypeSystem != NULL))) {
6158  xmlNodePtr last;
6159  /* Need a small "hack" here to assure DTD comes before
6160  possible comment nodes */
6161  node = res->children;
6162  last = res->last;
6163  res->children = NULL;
6164  res->last = NULL;
6165  res->intSubset = xmlCreateIntSubset(res, doctype,
6166  doctypePublic,
6167  doctypeSystem);
6168  if (res->children != NULL) {
6169  res->children->next = node;
6170  node->prev = res->children;
6171  res->last = last;
6172  } else {
6173  res->children = node;
6174  res->last = last;
6175  }
6176  }
6177  }
6178  }
6179  xmlXPathFreeNodeSet(ctxt->nodeList);
6180 
6181 #ifdef WITH_PROFILER
6182  if (profile != NULL) {
6183  xsltSaveProfiling(ctxt, profile);
6184  }
6185 #endif
6186 
6187  /*
6188  * Be pedantic.
6189  */
6190  if ((ctxt != NULL) && (ctxt->state != XSLT_STATE_OK)) {
6191  xmlFreeDoc(res);
6192  res = NULL;
6193  }
6194  if ((res != NULL) && (ctxt != NULL) && (output != NULL)) {
6195  int ret;
6196 
6197  ret = xsltCheckWrite(ctxt->sec, ctxt, (const xmlChar *) output);
6198  if (ret == 0) {
6199  xsltTransformError(ctxt, NULL, NULL,
6200  "xsltApplyStylesheet: forbidden to save to %s\n",
6201  output);
6202  } else if (ret < 0) {
6203  xsltTransformError(ctxt, NULL, NULL,
6204  "xsltApplyStylesheet: saving to %s may not be possible\n",
6205  output);
6206  }
6207  }
6208 
6209 #ifdef XSLT_DEBUG_PROFILE_CACHE
6210  printf("# Cache:\n");
6211  printf("# Reused tree fragments: %d\n", ctxt->cache->dbgReusedRVTs);
6212  printf("# Reused variables : %d\n", ctxt->cache->dbgReusedVars);
6213 #endif
6214 
6215  if ((ctxt != NULL) && (userCtxt == NULL))
6217 
6218  return (res);
6219 
6220 error:
6221  if (res != NULL)
6222  xmlFreeDoc(res);
6223 
6224 #ifdef XSLT_DEBUG_PROFILE_CACHE
6225  printf("# Cache:\n");
6226  printf("# Reused tree fragments: %d\n", ctxt->cache->dbgReusedRVTs);
6227  printf("# Reused variables : %d\n", ctxt->cache->dbgReusedVars);
6228 #endif
6229 
6230  if ((ctxt != NULL) && (userCtxt == NULL))
6232  return (NULL);
6233 }
xmlNodeSetPtr nodeList
static int xsltGetHTMLIDs(const xmlChar *version, const xmlChar **publicID, const xmlChar **systemID)
Definition: transform.c:5684
xsltTransformCachePtr cache
XMLPUBFUN int XMLCALL xmlDictReference(xmlDictPtr dict)
Definition: dict.c:645
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xsltStackElemPtr withParams)
Definition: transform.c:2106
xmlNodePtr initialContextNode
#define error(str)
Definition: mkdosfs.c:1605
void xsltFreeRVTs(xsltTransformContextPtr ctxt)
Definition: variables.c:421
struct _xmlDtd * intSubset
Definition: tree.h:570
int xslDebugStatus
Definition: xsltutils.c:2329
POINT last
Definition: font.c:46
struct _root root
XMLPUBFUN int XMLCALL xmlIsBlankNode(const xmlNode *node)
int xsltEvalGlobalVariables(xsltTransformContextPtr ctxt)
Definition: variables.c:1257
struct _xsltStackElem * next
void xsltShutdownCtxtExts(xsltTransformContextPtr ctxt)
Definition: extensions.c:1081
Definition: tree.h:406
struct node node
xsltTransformContextPtr xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc)
Definition: transform.c:536
GLenum const GLfloat * params
Definition: glext.h:5645
xsltTransformState state
static const WCHAR version[]
Definition: asmname.c:66
XMLPUBFUN void XMLCALL xmlFreeDtd(xmlDtdPtr cur)
xmlNode * xmlNodePtr
Definition: tree.h:488
xmlXPathContextPtr xpathCtxt
WDF_DMA_PROFILE profile
const xmlChar * modeURI
void * xsltGenericDebugContext
Definition: xsltutils.c:549
if(!(yy_init))
Definition: macro.lex.yy.c:714
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
XSLTPUBFUN void XSLTCALL xsltSaveProfiling(xsltTransformContextPtr ctxt, FILE *output)
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
Definition: dict.c:865
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
method
Definition: dragdrop.c:53
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreate(int size)
Definition: hash.c:181
Definition: tree.h:489
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
void xsltFreeTransformContext(xsltTransformContextPtr ctxt)
Definition: transform.c:690
XMLPUBFUN const xmlChar *XMLCALL xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name)
Definition: dict.c:1113
xmlElementType type
Definition: tree.h:491
ed encoding
Definition: write.c:2825
FxCollectionEntry * cur
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:276
void xsltFreeStackElemList(xsltStackElemPtr elem)
Definition: variables.c:608
const xmlChar * mode
struct _xmlNode * next
Definition: tree.h:496
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5712
XMLPUBFUN xmlDtdPtr XMLCALL xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
#define XSLT_GET_IMPORT_PTR(res, style, name)
Definition: imports.h:27
#define NULL
Definition: types.h:112
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
static int xsltCountKeys(xsltTransformContextPtr ctxt)
Definition: transform.c:5781
struct _xmlNode * last
Definition: tree.h:556
Definition: tree.h:551
XMLPUBFUN xmlDtdPtr XMLCALL xmlGetIntSubset(const xmlDoc *doc)
int xsltCheckWrite(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:335
void xsltCleanupTemplates(xsltStylesheetPtr style ATTRIBUTE_UNUSED)
Definition: pattern.c:2590
struct _xmlNode * children
Definition: tree.h:493
void xsltLocalVariablePop(xsltTransformContextPtr ctxt, int limitNr, int level)
Definition: transform.c:150
GLuint res
Definition: glext.h:9613
xmlXPathObjectPtr value
XMLPUBFUN xmlNodePtr XMLCALL xmlDocGetRootElement(const xmlDoc *doc)
struct _xmlNode * children
Definition: tree.h:555
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
void xsltInitGlobals(void)
Definition: extensions.c:2263
Arabic default style
Definition: afstyles.h:93
XMLPUBFUN xmlDocPtr XMLCALL xmlNewDoc(const xmlChar *version)
XMLPUBFUN int XMLCALL xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:271
xmlHashTablePtr globalVars
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
int xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params)
Definition: variables.c:1659
static void xsltReleaseLocalRVTs(xsltTransformContextPtr ctxt, xmlDocPtr base)
Definition: transform.c:2268
#define printf
Definition: config.h:203
Definition: dlist.c:348

Referenced by xsltApplyStylesheet(), xsltApplyStylesheetUser(), xsltProfileStylesheet(), and xsltRunStylesheetUser().

◆ xsltApplyStylesheetUser()

xmlDocPtr xsltApplyStylesheetUser ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params,
const char output,
FILE profile,
xsltTransformContextPtr  userCtxt 
)

xsltApplyStylesheetUser: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated array of parameters names/values tuples @output: the targetted output @profile: profile FILE * output or NULL @userCtxt: user provided transform context

Apply the stylesheet to the document and allow the user to provide its own transformation context.

Returns the result document or NULL in case of error

Definition at line 6290 of file transform.c.

6293 {
6294  xmlDocPtr res;
6295 
6297  profile, userCtxt);
6298  return (res);
6299 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
static xmlDocPtr xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
Definition: transform.c:5832
GLenum const GLfloat * params
Definition: glext.h:5645
WDF_DMA_PROFILE profile
Definition: tree.h:551
GLuint res
Definition: glext.h:9613
Arabic default style
Definition: afstyles.h:93

◆ xsltApplyTemplates()

void xsltApplyTemplates ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltApplyTemplates: @ctxt: a XSLT transformation context @node: the 'current node' in the source tree @inst: the element node of an XSLT 'apply-templates' instruction @castedComp: the compiled instruction

Processes the XSLT 'apply-templates' instruction on the current node.

Definition at line 4822 of file transform.c.

4824 {
4825 #ifdef XSLT_REFACTORED
4826  xsltStyleItemApplyTemplatesPtr comp =
4827  (xsltStyleItemApplyTemplatesPtr) castedComp;
4828 #else
4829  xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4830 #endif
4831  int i;
4832  xmlNodePtr cur, delNode = NULL, oldContextNode;
4833  xmlNodeSetPtr list = NULL, oldList;
4834  xsltStackElemPtr withParams = NULL;
4835  int oldXPProximityPosition, oldXPContextSize;
4836  const xmlChar *oldMode, *oldModeURI;
4837  xmlDocPtr oldXPDoc;
4838  xsltDocumentPtr oldDocInfo;
4839  xmlXPathContextPtr xpctxt;
4840 
4841  if (comp == NULL) {
4842  xsltTransformError(ctxt, NULL, inst,
4843  "xsl:apply-templates : compilation failed\n");
4844  return;
4845  }
4846  if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
4847  return;
4848 
4849 #ifdef WITH_XSLT_DEBUG_PROCESS
4850  if ((node != NULL) && (node->name != NULL))
4852  "xsltApplyTemplates: node: '%s'\n", node->name));
4853 #endif
4854 
4855  xpctxt = ctxt->xpathCtxt;
4856  /*
4857  * Save context states.
4858  */
4859  oldContextNode = ctxt->node;
4860  oldMode = ctxt->mode;
4861  oldModeURI = ctxt->modeURI;
4862  oldDocInfo = ctxt->document;
4863  oldList = ctxt->nodeList;
4864 
4865  /*
4866  * The xpath context size and proximity position, as
4867  * well as the xpath and context documents, may be changed
4868  * so we save their initial state and will restore on exit
4869  */
4870  oldXPContextSize = xpctxt->contextSize;
4871  oldXPProximityPosition = xpctxt->proximityPosition;
4872  oldXPDoc = xpctxt->doc;
4873 
4874  /*
4875  * Set up contexts.
4876  */
4877  ctxt->mode = comp->mode;
4878  ctxt->modeURI = comp->modeURI;
4879 
4880  if (comp->select != NULL) {
4881  xmlXPathObjectPtr res = NULL;
4882 
4883  if (comp->comp == NULL) {
4884  xsltTransformError(ctxt, NULL, inst,
4885  "xsl:apply-templates : compilation failed\n");
4886  goto error;
4887  }
4888 #ifdef WITH_XSLT_DEBUG_PROCESS
4890  "xsltApplyTemplates: select %s\n", comp->select));
4891 #endif
4892 
4893  res = xsltPreCompEval(ctxt, node, comp);
4894 
4895  if (res != NULL) {
4896  if (res->type == XPATH_NODESET) {
4897  list = res->nodesetval; /* consume the node set */
4898  res->nodesetval = NULL;
4899  } else {
4900  xsltTransformError(ctxt, NULL, inst,
4901  "The 'select' expression did not evaluate to a "
4902  "node set.\n");
4903  ctxt->state = XSLT_STATE_STOPPED;
4904  xmlXPathFreeObject(res);
4905  goto error;
4906  }
4907  xmlXPathFreeObject(res);
4908  /*
4909  * Note: An xsl:apply-templates with a 'select' attribute,
4910  * can change the current source doc.
4911  */
4912  } else {
4913  xsltTransformError(ctxt, NULL, inst,
4914  "Failed to evaluate the 'select' expression.\n");
4915  ctxt->state = XSLT_STATE_STOPPED;
4916  goto error;
4917  }
4918  if (list == NULL) {
4919 #ifdef WITH_XSLT_DEBUG_PROCESS
4921  "xsltApplyTemplates: select didn't evaluate to a node list\n"));
4922 #endif
4923  goto exit;
4924  }
4925  /*
4926  *
4927  * NOTE: Previously a document info (xsltDocument) was
4928  * created and attached to the Result Tree Fragment.
4929  * But such a document info is created on demand in
4930  * xsltKeyFunction() (functions.c), so we need to create
4931  * it here beforehand.
4932  * In order to take care of potential keys we need to
4933  * do some extra work for the case when a Result Tree Fragment
4934  * is converted into a nodeset (e.g. exslt:node-set()) :
4935  * We attach a "pseudo-doc" (xsltDocument) to _private.
4936  * This xsltDocument, together with the keyset, will be freed
4937  * when the Result Tree Fragment is freed.
4938  *
4939  */
4940 #if 0
4941  if ((ctxt->nbKeys > 0) &&
4942  (list->nodeNr != 0) &&
4943  (list->nodeTab[0]->doc != NULL) &&
4944  XSLT_IS_RES_TREE_FRAG(list->nodeTab[0]->doc))
4945  {
4946  /*
4947  * NOTE that it's also OK if @effectiveDocInfo will be
4948  * set to NULL.
4949  */
4950  isRTF = 1;
4951  effectiveDocInfo = list->nodeTab[0]->doc->_private;
4952  }
4953 #endif
4954  } else {
4955  /*
4956  * Build an XPath node set with the children
4957  */
4958  list = xmlXPathNodeSetCreate(NULL);
4959  if (list == NULL)
4960  goto error;
4961  if (node->type != XML_NAMESPACE_DECL)
4962  cur = node->children;
4963  else
4964  cur = NULL;
4965  while (cur != NULL) {
4966  switch (cur->type) {
4967  case XML_TEXT_NODE:
4968  if ((IS_BLANK_NODE(cur)) &&
4969  (cur->parent != NULL) &&
4970  (cur->parent->type == XML_ELEMENT_NODE) &&
4971  (ctxt->style->stripSpaces != NULL)) {
4972  const xmlChar *val;
4973 
4974  if (cur->parent->ns != NULL) {
4975  val = (const xmlChar *)
4977  cur->parent->name,
4978  cur->parent->ns->href);
4979  if (val == NULL) {
4980  val = (const xmlChar *)
4982  BAD_CAST "*",
4983  cur->parent->ns->href);
4984  }
4985  } else {
4986  val = (const xmlChar *)
4988  cur->parent->name, NULL);
4989  }
4990  if ((val != NULL) &&
4991  (xmlStrEqual(val, (xmlChar *) "strip"))) {
4992  delNode = cur;
4993  break;
4994  }
4995  }
4996  /* Intentional fall-through */
4997  case XML_ELEMENT_NODE:
4998  case XML_DOCUMENT_NODE:
5001  case XML_PI_NODE:
5002  case XML_COMMENT_NODE:
5003  xmlXPathNodeSetAddUnique(list, cur);
5004  break;
5005  case XML_DTD_NODE:
5006  /* Unlink the DTD, it's still reachable
5007  * using doc->intSubset */
5008  if (cur->next != NULL)
5009  cur->next->prev = cur->prev;
5010  if (cur->prev != NULL)
5011  cur->prev->next = cur->next;
5012  break;
5013  case XML_NAMESPACE_DECL:
5014  break;
5015  default:
5016 #ifdef WITH_XSLT_DEBUG_PROCESS
5018  "xsltApplyTemplates: skipping cur type %d\n",
5019  cur->type));
5020 #endif
5021  delNode = cur;
5022  }
5023  cur = cur->next;
5024  if (delNode != NULL) {
5025 #ifdef WITH_XSLT_DEBUG_PROCESS
5027  "xsltApplyTemplates: removing ignorable blank cur\n"));
5028 #endif
5029  xmlUnlinkNode(delNode);
5030  xmlFreeNode(delNode);
5031  delNode = NULL;
5032  }
5033  }
5034  }
5035 
5036 #ifdef WITH_XSLT_DEBUG_PROCESS
5037  if (list != NULL)
5039  "xsltApplyTemplates: list of %d nodes\n", list->nodeNr));
5040 #endif
5041 
5042  if ((list == NULL) || (list->nodeNr == 0))
5043  goto exit;
5044 
5045  /*
5046  * Set the context's node set and size; this is also needed for
5047  * for xsltDoSortFunction().
5048  */
5049  ctxt->nodeList = list;
5050  /*
5051  * Process xsl:with-param and xsl:sort instructions.
5052  * (The code became so verbose just to avoid the
5053  * xmlNodePtr sorts[XSLT_MAX_SORT] if there's no xsl:sort)
5054  * BUG TODO: We are not using namespaced potentially defined on the
5055  * xsl:sort or xsl:with-param elements; XPath expression might fail.
5056  */
5057  if (inst->children) {
5059 
5060  cur = inst->children;
5061  while (cur) {
5062 
5063 #ifdef WITH_DEBUGGER
5064  if (ctxt->debugStatus != XSLT_DEBUG_NONE)
5065  xslHandleDebugger(cur, node, NULL, ctxt);
5066 #endif
5067  if (ctxt->state == XSLT_STATE_STOPPED)
5068  break;
5069  if (cur->type == XML_TEXT_NODE) {
5070  cur = cur->next;
5071  continue;
5072  }
5073  if (! IS_XSLT_ELEM(cur))
5074  break;
5075  if (IS_XSLT_NAME(cur, "with-param")) {
5077  if (param != NULL) {
5078  param->next = withParams;
5079  withParams = param;
5080  }
5081  }
5082  if (IS_XSLT_NAME(cur, "sort")) {
5083  xsltTemplatePtr oldCurTempRule =
5084  ctxt->currentTemplateRule;
5085  int nbsorts = 0;
5086  xmlNodePtr sorts[XSLT_MAX_SORT];
5087 
5088  sorts[nbsorts++] = cur;
5089 
5090  while (cur) {
5091 
5092 #ifdef WITH_DEBUGGER
5093  if (ctxt->debugStatus != XSLT_DEBUG_NONE)
5094  xslHandleDebugger(cur, node, NULL, ctxt);
5095 #endif
5096  if (ctxt->state == XSLT_STATE_STOPPED)
5097  break;
5098 
5099  if (cur->type == XML_TEXT_NODE) {
5100  cur = cur->next;
5101  continue;
5102  }
5103 
5104  if (! IS_XSLT_ELEM(cur))
5105  break;
5106  if (IS_XSLT_NAME(cur, "with-param")) {
5108  if (param != NULL) {
5109  param->next = withParams;
5110  withParams = param;
5111  }
5112  }
5113  if (IS_XSLT_NAME(cur, "sort")) {
5114  if (nbsorts >= XSLT_MAX_SORT) {
5115  xsltTransformError(ctxt, NULL, cur,
5116  "The number (%d) of xsl:sort instructions exceeds the "
5117  "maximum allowed by this processor's settings.\n",
5118  nbsorts);
5119  ctxt->state = XSLT_STATE_STOPPED;
5120  break;
5121  } else {
5122  sorts[nbsorts++] = cur;
5123  }
5124  }
5125  cur = cur->next;
5126  }
5127  /*
5128  * The "current template rule" is cleared for xsl:sort.
5129  */
5130  ctxt->currentTemplateRule = NULL;
5131  /*
5132  * Sort.
5133  */
5134  xsltDoSortFunction(ctxt, sorts, nbsorts);
5135  ctxt->currentTemplateRule = oldCurTempRule;
5136  break;
5137  }
5138  cur = cur->next;
5139  }
5140  }
5141  xpctxt->contextSize = list->nodeNr;
5142  /*
5143  * Apply templates for all selected source nodes.
5144  */
5145  for (i = 0; i < list->nodeNr; i++) {
5146  cur = list->nodeTab[i];
5147  /*
5148  * The node becomes the "current node".
5149  */
5150  ctxt->node = cur;
5151  /*
5152  * An xsl:apply-templates can change the current context doc.
5153  * OPTIMIZE TODO: Get rid of the need to set the context doc.
5154  */
5155  if ((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL))
5156  xpctxt->doc = cur->doc;
5157 
5158  xpctxt->proximityPosition = i + 1;
5159  /*
5160  * Find and apply a template for this node.
5161  */
5162  xsltProcessOneNode(ctxt, cur, withParams);
5163  }
5164 
5165 exit:
5166 error:
5167  /*
5168  * Free the parameter list.
5169  */
5170  if (withParams != NULL)
5171  xsltFreeStackElemList(withParams);
5172  if (list != NULL)
5173  xmlXPathFreeNodeSet(list);
5174  /*
5175  * Restore context states.
5176  */
5177  xpctxt->doc = oldXPDoc;
5178  xpctxt->contextSize = oldXPContextSize;
5179  xpctxt->proximityPosition = oldXPProximityPosition;
5180 
5181  ctxt->document = oldDocInfo;
5182  ctxt->nodeList = oldList;
5183  ctxt->node = oldContextNode;
5184  ctxt->mode = oldMode;
5185  ctxt->modeURI = oldModeURI;
5186 }
xmlNodeSetPtr nodeList
void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xsltStackElemPtr withParams)
Definition: transform.c:2106
#define error(str)
Definition: mkdosfs.c:1605
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:481
xsltStackElemPtr xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr inst)
Definition: variables.c:1959
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
struct _xmlDoc * doc
Definition: tree.h:560
void xsltDoSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, int nbsorts)
Definition: xsltutils.c:1332
XSLTPUBFUN void XSLTCALL xslHandleDebugger(xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
const xmlChar * modeURI
#define XSLT_MAX_SORT
xsltTransformState state
#define IS_BLANK_NODE(n)
Definition: transform.c:47
#define BAD_CAST
Definition: xmlstring.h:35
xsltDocumentPtr document
xmlXPathContextPtr xpathCtxt
static xmlXPathObjectPtr xsltPreCompEval(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:321
GLuint GLfloat * val
Definition: glext.h:7180
const xmlChar * modeURI
void * xsltGenericDebugContext
Definition: xsltutils.c:549
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
GLfloat param
Definition: glext.h:5796
xsltTemplatePtr currentTemplateRule
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
unsigned char xmlChar
Definition: xmlstring.h:28
Definition: _list.h:228
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
FxCollectionEntry * cur
xsltStylePreComp * xsltStylePreCompPtr
void xsltFreeStackElemList(xsltStackElemPtr elem)
Definition: variables.c:608
xsltStylesheetPtr style
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
#define XSLT_IS_RES_TREE_FRAG(n)
Definition: xsltInternals.h:56
const xmlChar * mode
xmlXPathCompExprPtr comp
#define list
Definition: rosglue.h:35
#define NULL
Definition: types.h:112
Definition: tree.h:551
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
const xmlChar * select
struct _xmlNode * children
Definition: tree.h:493
GLuint res
Definition: glext.h:9613
xmlHashTablePtr stripSpaces
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
void exit(int exitcode)
Definition: _exit.c:33
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
#define IS_XSLT_NAME(n, val)
Definition: xsltutils.h:63
const xmlChar * mode
Definition: dlist.c:348

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltApplyXSLTTemplate()

static void xsltApplyXSLTTemplate ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  list,
xsltTemplatePtr  templ,
xsltStackElemPtr  withParams 
)
static

Definition at line 3068 of file transform.c.

3073 {
3074  int oldVarsBase = 0;
3075  xmlNodePtr cur;
3076  xsltStackElemPtr tmpParam = NULL;
3077  xmlDocPtr oldUserFragmentTop;
3078 #ifdef WITH_PROFILER
3079  long start = 0;
3080 #endif
3081 
3082 #ifdef XSLT_REFACTORED
3083  xsltStyleItemParamPtr iparam;
3084 #else
3085  xsltStylePreCompPtr iparam;
3086 #endif
3087 
3088 #ifdef WITH_DEBUGGER
3089  int addCallResult = 0;
3090 #endif
3091 
3092  if (ctxt == NULL)
3093  return;
3094  if (templ == NULL) {
3095  xsltTransformError(ctxt, NULL, list,
3096  "xsltApplyXSLTTemplate: Bad arguments; @templ is mandatory.\n");
3097  return;
3098  }
3099 
3100 #ifdef WITH_DEBUGGER
3101  if (ctxt->debugStatus != XSLT_DEBUG_NONE) {
3102  if (xsltDebuggerStartSequenceConstructor(ctxt, contextNode,
3103  list, templ, &addCallResult) == NULL)
3104  return;
3105  }
3106 #endif
3107 
3108  if (list == NULL)
3109  return;
3110  CHECK_STOPPED;
3111 
3112  if (ctxt->varsNr >= ctxt->maxTemplateVars)
3113  {
3114  xsltTransformError(ctxt, NULL, list,
3115  "xsltApplyXSLTTemplate: A potential infinite template recursion "
3116  "was detected.\n"
3117  "You can adjust maxTemplateVars (--maxvars) in order to "
3118  "raise the maximum number of variables/params (currently set to %d).\n",
3119  ctxt->maxTemplateVars);
3120  xsltDebug(ctxt, contextNode, list, NULL);
3121  ctxt->state = XSLT_STATE_STOPPED;
3122  return;
3123  }
3124 
3125  oldUserFragmentTop = ctxt->tmpRVT;
3126  ctxt->tmpRVT = NULL;
3127 
3128  /*
3129  * Initiate a distinct scope of local params/variables.
3130  */
3131  oldVarsBase = ctxt->varsBase;
3132  ctxt->varsBase = ctxt->varsNr;
3133 
3134  ctxt->node = contextNode;
3135 
3136 #ifdef WITH_PROFILER
3137  if (ctxt->profile) {
3138  templ->nbCalls++;
3139  start = xsltTimestamp();
3140  profPush(ctxt, 0);
3141  profCallgraphAdd(templ, ctxt->templ);
3142  }
3143 #endif
3144 
3145  /*
3146  * Push the xsl:template declaration onto the stack.
3147  */
3148  templPush(ctxt, templ);
3149 
3150 #ifdef WITH_XSLT_DEBUG_PROCESS
3151  if (templ->name != NULL)
3153  "applying xsl:template '%s'\n", templ->name));
3154 #endif
3155  /*
3156  * Process xsl:param instructions and skip those elements for
3157  * further processing.
3158  */
3159  cur = list;
3160  do {
3161  if (cur->type == XML_TEXT_NODE) {
3162  cur = cur->next;
3163  continue;
3164  }
3165  if ((cur->type != XML_ELEMENT_NODE) ||
3166  (cur->name[0] != 'p') ||
3167  (cur->psvi == NULL) ||
3168  (! xmlStrEqual(cur->name, BAD_CAST "param")) ||
3169  (! IS_XSLT_ELEM(cur)))
3170  {
3171  break;
3172  }
3173 
3174  list = cur->next;
3175 
3176 #ifdef XSLT_REFACTORED
3177  iparam = (xsltStyleItemParamPtr) cur->psvi;
3178 #else
3179  iparam = (xsltStylePreCompPtr) cur->psvi;
3180 #endif
3181 
3182  /*
3183  * Substitute xsl:param for a given xsl:with-param.
3184  * Since the XPath expression will reference the params/vars
3185  * by index, we need to slot the xsl:with-params in the
3186  * order of encountered xsl:params to keep the sequence of
3187  * params/variables in the stack exactly as it was at
3188  * compile time,
3189  */
3190  tmpParam = NULL;
3191  if (withParams) {
3192  tmpParam = withParams;
3193  do {
3194  if ((tmpParam->name == (iparam->name)) &&
3195  (tmpParam->nameURI == (iparam->ns)))
3196  {
3197  /*
3198  * Push the caller-parameter.
3199  */
3200  xsltLocalVariablePush(ctxt, tmpParam, -1);
3201  break;
3202  }
3203  tmpParam = tmpParam->next;
3204  } while (tmpParam != NULL);
3205  }
3206  /*
3207  * Push the xsl:param.
3208  */
3209  if (tmpParam == NULL) {
3210  /*
3211  * Note that we must assume that the added parameter
3212  * has a @depth of 0.
3213  */
3215  }
3216  cur = cur->next;
3217  } while (cur != NULL);
3218  /*
3219  * Process the sequence constructor.
3220  */
3221  xsltApplySequenceConstructor(ctxt, contextNode, list, templ);
3222 
3223  /*
3224  * Remove remaining xsl:param and xsl:with-param items from
3225  * the stack. Don't free xsl:with-param items.
3226  */
3227  if (ctxt->varsNr > ctxt->varsBase)
3229  ctxt->varsBase = oldVarsBase;
3230 
3231  /*
3232  * Release user-created fragments stored in the scope
3233  * of xsl:template. Note that this mechanism is deprecated:
3234  * user code should now use xsltRegisterLocalRVT() instead
3235  * of the obsolete xsltRegisterTmpRVT().
3236  */
3237  if (ctxt->tmpRVT) {
3238  xmlDocPtr curdoc = ctxt->tmpRVT, tmp;
3239 
3240  while (curdoc != NULL) {
3241  tmp = curdoc;
3242  curdoc = (xmlDocPtr) curdoc->next;
3243  xsltReleaseRVT(ctxt, tmp);
3244  }
3245  }
3246  ctxt->tmpRVT = oldUserFragmentTop;
3247 
3248  /*
3249  * Pop the xsl:template declaration from the stack.
3250  */
3251  templPop(ctxt);
3252 
3253 #ifdef WITH_PROFILER
3254  if (ctxt->profile) {
3255  long spent, child, total, end;
3256 
3257  end = xsltTimestamp();
3258  child = profPop(ctxt);
3259  total = end - start;
3260  spent = total - child;
3261  if (spent <= 0) {
3262  /*
3263  * Not possible unless the original calibration failed
3264  * we can try to correct it on the fly.
3265  */
3266  xsltCalibrateAdjust(spent);
3267  spent = 0;
3268  }
3269 
3270  templ->time += spent;
3271  if (ctxt->profNr > 0)
3272  ctxt->profTab[ctxt->profNr - 1] += total;
3273  }
3274 #endif
3275 
3276 #ifdef WITH_DEBUGGER
3277  if ((ctxt->debugStatus != XSLT_DEBUG_NONE) && (addCallResult)) {
3278  xslDropCall();
3279  }
3280 #endif
3281 }
const xmlChar * name
XSLTPUBFUN void XSLTCALL xsltCalibrateAdjust(long delta)
void xsltParseStylesheetParam(xsltTransformContextPtr ctxt, xmlNodePtr cur)
Definition: variables.c:2188
const xmlChar * ns
void xsltReleaseRVT(xsltTransformContextPtr ctxt, xmlDocPtr RVT)
Definition: variables.c:328
struct _xsltStackElem * next
XSLTPUBFUN long XSLTCALL xsltTimestamp(void)
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
static HWND child
Definition: cursoricon.c:298
#define CHECK_STOPPED
XSLTPUBFUN void XSLTCALL xslDropCall(void)
xsltTransformState state
#define BAD_CAST
Definition: xmlstring.h:35
static int templPush(xsltTransformContextPtr ctxt, xsltTemplatePtr value)
Definition: transform.c:85
void * xsltGenericDebugContext
Definition: xsltutils.c:549
int xsltLocalVariablePush(xsltTransformContextPtr ctxt, xsltStackElemPtr variable, int level)
Definition: transform.c:2230
xsltTemplatePtr templ
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
const xmlChar * nameURI
GLuint GLuint end
Definition: gl.h:1545
Definition: tree.h:489
struct _xmlNode * next
Definition: tree.h:558
static xsltTemplatePtr templPop(xsltTransformContextPtr ctxt)
Definition: transform.c:121
unsigned long time
Definition: _list.h:228
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
FxCollectionEntry * cur
xmlDoc * xmlDocPtr
Definition: tree.h:550
GLuint start
Definition: gl.h:1545
#define list
Definition: rosglue.h:35
#define NULL
Definition: types.h:112
size_t total
Definition: tree.h:551
const xmlChar * name
static void xsltTemplateParamsCleanup(xsltTransformContextPtr ctxt)
Definition: transform.c:180
void xsltDebug(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst ATTRIBUTE_UNUSED, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: extra.c:35
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
const xmlChar * name

Referenced by xsltApplyImports(), xsltCallTemplate(), xsltDefaultProcessOneNode(), and xsltProcessOneNode().

◆ xsltCallTemplate()

void xsltCallTemplate ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltCallTemplate: @ctxt: a XSLT transformation context @node: the "current node" in the source tree @inst: the XSLT 'call-template' instruction @castedComp: the compiled information of the instruction

Processes the XSLT call-template instruction on the source node.

Definition at line 4719 of file transform.c.

4721 {
4722 #ifdef XSLT_REFACTORED
4723  xsltStyleItemCallTemplatePtr comp =
4724  (xsltStyleItemCallTemplatePtr) castedComp;
4725 #else
4726  xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4727 #endif
4728  xsltStackElemPtr withParams = NULL;
4729 
4730  if (ctxt->insert == NULL)
4731  return;
4732  if (comp == NULL) {
4733  xsltTransformError(ctxt, NULL, inst,
4734  "The XSLT 'call-template' instruction was not compiled.\n");
4735  return;
4736  }
4737 
4738  /*
4739  * The template must have been precomputed
4740  */
4741  if (comp->templ == NULL) {
4742  comp->templ = xsltFindTemplate(ctxt, comp->name, comp->ns);
4743  if (comp->templ == NULL) {
4744  if (comp->ns != NULL) {
4745  xsltTransformError(ctxt, NULL, inst,
4746  "The called template '{%s}%s' was not found.\n",
4747  comp->ns, comp->name);
4748  } else {
4749  xsltTransformError(ctxt, NULL, inst,
4750  "The called template '%s' was not found.\n",
4751  comp->name);
4752  }
4753  return;
4754  }
4755  }
4756 
4757 #ifdef WITH_XSLT_DEBUG_PROCESS
4758  if ((comp != NULL) && (comp->name != NULL))
4760  "call-template: name %s\n", comp->name));
4761 #endif
4762 
4763  if (inst->children) {
4764  xmlNodePtr cur;
4766 
4767  cur = inst->children;
4768  while (cur != NULL) {
4769 #ifdef WITH_DEBUGGER
4770  if (ctxt->debugStatus != XSLT_DEBUG_NONE)
4771  xslHandleDebugger(cur, node, comp->templ, ctxt);
4772 #endif
4773  if (ctxt->state == XSLT_STATE_STOPPED) break;
4774  /*
4775  * TODO: The "with-param"s could be part of the "call-template"
4776  * structure. Avoid to "search" for params dynamically
4777  * in the XML tree every time.
4778  */
4779  if (IS_XSLT_ELEM(cur)) {
4780  if (IS_XSLT_NAME(cur, "with-param")) {
4782  if (param != NULL) {
4783  param->next = withParams;
4784  withParams = param;
4785  }
4786  } else {
4788  "xsl:call-template: misplaced xsl:%s\n", cur->name);
4789  }
4790  } else {
4792  "xsl:call-template: misplaced %s element\n", cur->name);
4793  }
4794  cur = cur->next;
4795  }
4796  }
4797  /*
4798  * Create a new frame using the params first
4799  */
4800  xsltApplyXSLTTemplate(ctxt, node, comp->templ->content, comp->templ,
4801  withParams);
4802  if (withParams != NULL)
4803  xsltFreeStackElemList(withParams);
4804 
4805 #ifdef WITH_XSLT_DEBUG_PROCESS
4806  if ((comp != NULL) && (comp->name != NULL))
4808  "call-template returned: name %s\n", comp->name));
4809 #endif
4810 }
xsltTemplatePtr xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI)
Definition: imports.c:357
const xmlChar * ns
xmlNodePtr content
static void xsltApplyXSLTTemplate(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ, xsltStackElemPtr withParams)
Definition: transform.c:3068
xsltStackElemPtr xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr inst)
Definition: variables.c:1959
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
XSLTPUBFUN void XSLTCALL xslHandleDebugger(xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
xmlGenericErrorFunc xsltGenericError
Definition: xsltutils.c:502
xsltTransformState state
xsltTemplatePtr templ
void * xsltGenericDebugContext
Definition: xsltutils.c:549
GLfloat param
Definition: glext.h:5796
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
void * xsltGenericErrorContext
Definition: xsltutils.c:503
Definition: tree.h:489
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
FxCollectionEntry * cur
xsltStylePreComp * xsltStylePreCompPtr
void xsltFreeStackElemList(xsltStackElemPtr elem)
Definition: variables.c:608
#define NULL
Definition: types.h:112
const xmlChar * name
struct _xmlNode * children
Definition: tree.h:493
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
#define IS_XSLT_NAME(n, val)
Definition: xsltutils.h:63
Definition: dlist.c:348

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltChoose()

void xsltChoose ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst,
xsltElemPreCompPtr comp  ATTRIBUTE_UNUSED 
)

xsltChoose: @ctxt: a XSLT process context @contextNode: the current node in the source tree @inst: the xsl:choose instruction @comp: compiled information of the instruction

Processes the xsl:choose instruction on the source node.

Definition at line 5199 of file transform.c.

5201 {
5202  xmlNodePtr cur;
5203 
5204  if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL))
5205  return;
5206 
5207  /*
5208  * TODO: Content model checks should be done only at compilation
5209  * time.
5210  */
5211  cur = inst->children;
5212  if (cur == NULL) {
5213  xsltTransformError(ctxt, NULL, inst,
5214  "xsl:choose: The instruction has no content.\n");
5215  return;
5216  }
5217 
5218 #ifdef XSLT_REFACTORED
5219  /*
5220  * We don't check the content model during transformation.
5221  */
5222 #else
5223  if ((! IS_XSLT_ELEM(cur)) || (! IS_XSLT_NAME(cur, "when"))) {
5224  xsltTransformError(ctxt, NULL, inst,
5225  "xsl:choose: xsl:when expected first\n");
5226  return;
5227  }
5228 #endif
5229 
5230  {
5231  int testRes = 0, res = 0;
5232 
5233 #ifdef XSLT_REFACTORED
5234  xsltStyleItemWhenPtr wcomp = NULL;
5235 #else
5236  xsltStylePreCompPtr wcomp = NULL;
5237 #endif
5238 
5239  /*
5240  * Process xsl:when ---------------------------------------------------
5241  */
5242  while (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "when")) {
5243  wcomp = cur->psvi;
5244 
5245  if ((wcomp == NULL) || (wcomp->test == NULL) ||
5246  (wcomp->comp == NULL))
5247  {
5248  xsltTransformError(ctxt, NULL, cur,
5249  "Internal error in xsltChoose(): "
5250  "The XSLT 'when' instruction was not compiled.\n");
5251  goto error;
5252  }
5253 
5254 
5255 #ifdef WITH_DEBUGGER
5257  /*
5258  * TODO: Isn't comp->templ always NULL for xsl:choose?
5259  */
5260  xslHandleDebugger(cur, contextNode, NULL, ctxt);
5261  }
5262 #endif
5263 #ifdef WITH_XSLT_DEBUG_PROCESS
5265  "xsltChoose: test %s\n", wcomp->test));
5266 #endif
5267 
5268 #ifdef XSLT_FAST_IF
5269  res = xsltPreCompEvalToBoolean(ctxt, contextNode, wcomp);
5270 
5271  if (res == -1) {
5272  ctxt->state = XSLT_STATE_STOPPED;
5273  goto error;
5274  }
5275  testRes = (res == 1) ? 1 : 0;
5276 
5277 #else /* XSLT_FAST_IF */
5278 
5279  res = xsltPreCompEval(ctxt, cotextNode, wcomp);
5280 
5281  if (res != NULL) {
5282  if (res->type != XPATH_BOOLEAN)
5283  res = xmlXPathConvertBoolean(res);
5284  if (res->type == XPATH_BOOLEAN)
5285  testRes = res->boolval;
5286  else {
5287 #ifdef WITH_XSLT_DEBUG_PROCESS
5289  "xsltChoose: test didn't evaluate to a boolean\n"));
5290 #endif
5291  goto error;
5292  }
5293  xmlXPathFreeObject(res);
5294  res = NULL;
5295  } else {
5296  ctxt->state = XSLT_STATE_STOPPED;
5297  goto error;
5298  }
5299 
5300 #endif /* else of XSLT_FAST_IF */
5301 
5302 #ifdef WITH_XSLT_DEBUG_PROCESS
5304  "xsltChoose: test evaluate to %d\n", testRes));
5305 #endif
5306  if (testRes)
5307  goto test_is_true;
5308 
5309  cur = cur->next;
5310  }
5311 
5312  /*
5313  * Process xsl:otherwise ----------------------------------------------
5314  */
5315  if (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "otherwise")) {
5316 
5317 #ifdef WITH_DEBUGGER
5319  xslHandleDebugger(cur, contextNode, NULL, ctxt);
5320 #endif
5321 
5322 #ifdef WITH_XSLT_DEBUG_PROCESS
5324  "evaluating xsl:otherwise\n"));
5325 #endif
5326  goto test_is_true;
5327  }
5328  goto exit;
5329 
5330 test_is_true:
5331 
5332  goto process_sequence;
5333  }
5334 
5335 process_sequence:
5336 
5337  /*
5338  * Instantiate the sequence constructor.
5339  */
5340  xsltApplySequenceConstructor(ctxt, ctxt->node, cur->children,
5341  NULL);
5342 
5343 exit:
5344 error:
5345  return;
5346 }
#define error(str)
Definition: mkdosfs.c:1605
const xmlChar * test
int xslDebugStatus
Definition: xsltutils.c:2329
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:54
XSLTPUBFUN void XSLTCALL xslHandleDebugger(xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
xsltTransformState state
static xmlXPathObjectPtr xsltPreCompEval(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:321
static int xsltPreCompEvalToBoolean(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:370
void * xsltGenericDebugContext
Definition: xsltutils.c:549
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
FxCollectionEntry * cur
xmlXPathCompExprPtr comp
#define NULL
Definition: types.h:112
struct _xmlNode * children
Definition: tree.h:493
GLuint res
Definition: glext.h:9613
void exit(int exitcode)
Definition: _exit.c:33
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
#define IS_XSLT_NAME(n, val)
Definition: xsltutils.h:63

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltComment()

void xsltComment ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr comp  ATTRIBUTE_UNUSED 
)

xsltComment: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the xslt comment node @comp: precomputed information

Process the xslt comment node on the source node

Definition at line 4265 of file transform.c.

4266  {
4267  xmlChar *value = NULL;
4268  xmlNodePtr commentNode;
4269  int len;
4270 
4271  value = xsltEvalTemplateString(ctxt, node, inst);
4272  /* TODO: use or generate the compiled form */
4273  len = xmlStrlen(value);
4274  if (len > 0) {
4275  if ((value[len-1] == '-') ||
4276  (xmlStrstr(value, BAD_CAST "--"))) {
4277  xsltTransformError(ctxt, NULL, inst,
4278  "xsl:comment : '--' or ending '-' not allowed in comment\n");
4279  /* fall through to try to catch further errors */
4280  }
4281  }
4282 #ifdef WITH_XSLT_DEBUG_PROCESS
4283  if (value == NULL) {
4285  "xsltComment: empty\n"));
4286  } else {
4288  "xsltComment: content %s\n", value));
4289  }
4290 #endif
4291 
4292  commentNode = xmlNewComment(value);
4293  commentNode = xsltAddChild(ctxt->insert, commentNode);
4294 
4295  if (value != NULL)
4296  xmlFree(value);
4297 }
XMLPUBFUN const xmlChar *XMLCALL xmlStrstr(const xmlChar *str, const xmlChar *val)
Definition: xmlstring.c:341
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:752
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
#define BAD_CAST
Definition: xmlstring.h:35
void * xsltGenericDebugContext
Definition: xsltutils.c:549
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
XMLPUBFUN xmlNodePtr XMLCALL xmlNewComment(const xmlChar *content)
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
#define NULL
Definition: types.h:112
xmlChar * xsltEvalTemplateString(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst)
Definition: templates.c:189
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
Definition: dlist.c:348

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopy()

void xsltCopy ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltCopy: @ctxt: an XSLT process context @node: the node in the source tree @inst: the element node of the XSLT-copy instruction @castedComp: computed information of the XSLT-copy instruction

Execute the XSLT-copy instruction on the source node.

Definition at line 3901 of file transform.c.

3903 {
3904 #ifdef XSLT_REFACTORED
3905  xsltStyleItemCopyPtr comp = (xsltStyleItemCopyPtr) castedComp;
3906 #else
3907  xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
3908 #endif
3909  xmlNodePtr copy, oldInsert;
3910 
3911  oldInsert = ctxt->insert;
3912  if (ctxt->insert != NULL) {
3913  switch (node->type) {
3914  case XML_TEXT_NODE:
3916  /*
3917  * This text comes from the stylesheet
3918  * For stylesheets, the set of whitespace-preserving
3919  * element names consists of just xsl:text.
3920  */
3921 #ifdef WITH_XSLT_DEBUG_PROCESS
3922  if (node->type == XML_CDATA_SECTION_NODE) {
3924  "xsltCopy: CDATA text %s\n", node->content));
3925  } else {
3927  "xsltCopy: text %s\n", node->content));
3928  }
3929 #endif
3930  xsltCopyText(ctxt, ctxt->insert, node, 0);
3931  break;
3932  case XML_DOCUMENT_NODE:
3934  break;
3935  case XML_ELEMENT_NODE:
3936  /*
3937  * REVISIT NOTE: The "fake" is a doc-node, not an element node.
3938  * REMOVED:
3939  * if (xmlStrEqual(node->name, BAD_CAST " fake node libxslt"))
3940  * return;
3941  */
3942 
3943 #ifdef WITH_XSLT_DEBUG_PROCESS
3945  "xsltCopy: node %s\n", node->name));
3946 #endif
3947  copy = xsltShallowCopyElem(ctxt, node, ctxt->insert, 0);
3948  ctxt->insert = copy;
3949  if (comp->use != NULL) {
3950  xsltApplyAttributeSet(ctxt, node, inst, comp->use);
3951  }
3952  break;
3953  case XML_ATTRIBUTE_NODE: {
3954 #ifdef WITH_XSLT_DEBUG_PROCESS
3956  "xsltCopy: attribute %s\n", node->name));
3957 #endif
3958  /*
3959  * REVISIT: We could also raise an error if the parent is not
3960  * an element node.
3961  * OPTIMIZE TODO: Can we set the value/children of the
3962  * attribute without an intermediate copy of the string value?
3963  */
3964  xsltShallowCopyAttr(ctxt, inst, ctxt->insert, (xmlAttrPtr) node);
3965  break;
3966  }
3967  case XML_PI_NODE:
3968 #ifdef WITH_XSLT_DEBUG_PROCESS
3970  "xsltCopy: PI %s\n", node->name));
3971 #endif
3972  copy = xmlNewDocPI(ctxt->insert->doc, node->name,
3973  node->content);
3974  copy = xsltAddChild(ctxt->insert, copy);
3975  break;
3976  case XML_COMMENT_NODE:
3977 #ifdef WITH_XSLT_DEBUG_PROCESS
3979  "xsltCopy: comment\n"));
3980 #endif
3981  copy = xmlNewComment(node->content);
3982  copy = xsltAddChild(ctxt->insert, copy);
3983  break;
3984  case XML_NAMESPACE_DECL:
3985 #ifdef WITH_XSLT_DEBUG_PROCESS
3987  "xsltCopy: namespace declaration\n"));
3988 #endif
3989  xsltShallowCopyNsNode(ctxt, inst, ctxt->insert, (xmlNsPtr)node);
3990  break;
3991  default:
3992  break;
3993 
3994  }
3995  }
3996 
3997  switch (node->type) {
3998  case XML_DOCUMENT_NODE:
4000  case XML_ELEMENT_NODE:
4001  xsltApplySequenceConstructor(ctxt, ctxt->node, inst->children,
4002  NULL);
4003  break;
4004  default:
4005  break;
4006  }
4007  ctxt->insert = oldInsert;
4008 }
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:752
const xmlChar * use
Definition: tree.h:389
static xmlNodePtr xsltCopyText(xsltTransformContextPtr ctxt, xmlNodePtr target, xmlNodePtr cur, int interned)
Definition: transform.c:946
struct _xmlDoc * doc
Definition: tree.h:498
static xmlAttrPtr xsltShallowCopyAttr(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr target, xmlAttrPtr attr)
Definition: transform.c:1122
void * xsltGenericDebugContext
Definition: xsltutils.c:549
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content)
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
void xsltApplyAttributeSet(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, const xmlChar *attrSets)
Definition: attributes.c:1086
XMLPUBFUN xmlNodePtr XMLCALL xmlNewComment(const xmlChar *content)
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2320
xsltStylePreComp * xsltStylePreCompPtr
static xmlNodePtr xsltShallowCopyElem(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr insert, int isLRE)
Definition: transform.c:1297
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
struct _xmlNode * children
Definition: tree.h:493
Definition: tree.h:434
static xmlNsPtr xsltShallowCopyNsNode(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr insert, xmlNsPtr ns)
Definition: transform.c:1482
Definition: dlist.c:348

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopyAttrListNoOverwrite()

static int xsltCopyAttrListNoOverwrite ( xsltTransformContextPtr  ctxt,
xmlNodePtr  invocNode,
xmlNodePtr  target,
xmlAttrPtr  attr 
)
static

xsltCopyAttrListNoOverwrite: @ctxt: a XSLT process context @invocNode: responsible node in the stylesheet; used for error reports @target: the element where the new attributes will be grafted @attr: the first attribute in the list to be copied

Copies a list of attribute nodes, starting with @attr, over to the @target element node.

Called by:

Returns 0 on success and -1 on errors and internal errors.

Definition at line 1221 of file transform.c.

1224 {
1225  xmlAttrPtr copy;
1226  xmlNsPtr origNs = NULL, copyNs = NULL;
1227  xmlChar *value;
1228 
1229  /*
1230  * Don't use xmlCopyProp() here, since it will try to
1231  * reconciliate namespaces.
1232  */
1233  while (attr != NULL) {
1234  /*
1235  * Find a namespace node in the tree of @target.
1236  * Avoid searching for the same ns.
1237  */
1238  if (attr->ns != origNs) {
1239  origNs = attr->ns;
1240  if (attr->ns != NULL) {
1241  copyNs = xsltGetSpecialNamespace(ctxt, invocNode,
1242  attr->ns->href, attr->ns->prefix, target);
1243  if (copyNs == NULL)
1244  return(-1);
1245  } else
1246  copyNs = NULL;
1247  }
1248  /*
1249  * If attribute has a value, we need to copy it (watching out
1250  * for possible entities)
1251  */
1252  if ((attr->children) && (attr->children->type == XML_TEXT_NODE) &&
1253  (attr->children->next == NULL)) {
1254  copy = xmlNewNsProp(target, copyNs, attr->name,
1255  attr->children->content);
1256  } else if (attr->children != NULL) {
1257  value = xmlNodeListGetString(attr->doc, attr->children, 1);
1258  copy = xmlNewNsProp(target, copyNs, attr->name, BAD_CAST value);
1259  xmlFree(value);
1260  } else {
1261  copy = xmlNewNsProp(target, copyNs, attr->name, NULL);
1262  }
1263 
1264  if (copy == NULL)
1265  return(-1);
1266 
1267  attr = attr->next;
1268  }
1269  return(0);
1270 }
Definition: tree.h:389
xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, const xmlChar *nsName, const xmlChar *nsPrefix, xmlNodePtr target)
Definition: namespaces.c:299
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
Definition: cookie.c:201
XMLPUBFUN xmlChar *XMLCALL xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine)
XMLPUBFUN xmlAttrPtr XMLCALL xmlNewNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, const xmlChar *value)
unsigned char xmlChar
Definition: xmlstring.h:28
GLsizei const GLfloat * value
Definition: glext.h:6069
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
Definition: tree.h:434
WCHAR * name
Definition: cookie.c:203
GLenum target
Definition: glext.h:7315

Referenced by xsltCopyTree().

◆ xsltCopyNamespaceListInternal()

static xmlNsPtr xsltCopyNamespaceListInternal ( xmlNodePtr  elem,
xmlNsPtr  ns 
)
static

xsltCopyNamespaceListInternal: @node: the target node @cur: the first namespace

Do a copy of a namespace list. If @node is non-NULL the new namespaces are added automatically. Called by: xsltCopyTree()

QUESTION: What is the exact difference between this function and xsltCopyNamespaceList() in "namespaces.c"? ANSWER: xsltCopyNamespaceList() tries to apply ns-aliases.

Returns: a new xmlNsPtr, or NULL in case of error.

Definition at line 1425 of file transform.c.

1425  {
1426  xmlNsPtr ret = NULL;
1427  xmlNsPtr p = NULL, q, luNs;
1428 
1429  if (ns == NULL)
1430  return(NULL);
1431  /*
1432  * One can add namespaces only on element nodes
1433  */
1434  if ((elem != NULL) && (elem->type != XML_ELEMENT_NODE))
1435  elem = NULL;
1436 
1437  do {
1438  if (ns->type != XML_NAMESPACE_DECL)
1439  break;
1440  /*
1441  * Avoid duplicating namespace declarations on the tree.
1442  */
1443  if (elem != NULL) {
1444  if ((elem->ns != NULL) &&
1445  xmlStrEqual(elem->ns->prefix, ns->prefix) &&
1446  xmlStrEqual(elem->ns->href, ns->href))
1447  {
1448  ns = ns->next;
1449  continue;
1450  }
1451  luNs = xmlSearchNs(elem->doc, elem, ns->prefix);
1452  if ((luNs != NULL) && (xmlStrEqual(luNs->href, ns->href)))
1453  {
1454  ns = ns->next;
1455  continue;
1456  }
1457  }
1458  q = xmlNewNs(elem, ns->href, ns->prefix);
1459  if (p == NULL) {
1460  ret = p = q;
1461  } else if (q != NULL) {
1462  p->next = q;
1463  p = q;
1464  }
1465  ns = ns->next;
1466  } while (ns != NULL);
1467  return(ret);
1468 }
Definition: tree.h:389
static size_t elem
Definition: string.c:68
XMLPUBFUN xmlNsPtr XMLCALL xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace)
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
int ret
Definition: mxnamespace.c:44
BSTR prefix
Definition: mxnamespace.c:46
XMLPUBFUN xmlNsPtr XMLCALL xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix)
#define NULL
Definition: types.h:112
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by xsltCopyTree(), and xsltShallowCopyElem().

◆ xsltCopyOf()

void xsltCopyOf ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltCopyOf: @ctxt: an XSLT transformation context @node: the current node in the source tree @inst: the element node of the XSLT copy-of instruction @castedComp: precomputed information of the XSLT copy-of instruction

Process the XSLT copy-of instruction.

Definition at line 4375 of file transform.c.

4376  {
4377 #ifdef XSLT_REFACTORED
4378  xsltStyleItemCopyOfPtr comp = (xsltStyleItemCopyOfPtr) castedComp;
4379 #else
4380  xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4381 #endif
4382  xmlXPathObjectPtr res = NULL;
4383  xmlNodeSetPtr list = NULL;
4384  int i;
4385 
4386  if ((ctxt == NULL) || (node == NULL) || (inst == NULL))
4387  return;
4388  if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) {
4389  xsltTransformError(ctxt, NULL, inst,
4390  "xsl:copy-of : compilation failed\n");
4391  return;
4392  }
4393 
4394  /*
4395  * SPEC XSLT 1.0:
4396  * "The xsl:copy-of element can be used to insert a result tree
4397  * fragment into the result tree, without first converting it to
4398  * a string as xsl:value-of does (see [7.6.1 Generating Text with
4399  * xsl:value-of]). The required select attribute contains an
4400  * expression. When the result of evaluating the expression is a
4401  * result tree fragment, the complete fragment is copied into the
4402  * result tree. When the result is a node-set, all the nodes in the
4403  * set are copied in document order into the result tree; copying
4404  * an element node copies the attribute nodes, namespace nodes and
4405  * children of the element node as well as the element node itself;
4406  * a root node is copied by copying its children. When the result
4407  * is neither a node-set nor a result tree fragment, the result is
4408  * converted to a string and then inserted into the result tree,
4409  * as with xsl:value-of.
4410  */
4411 
4412 #ifdef WITH_XSLT_DEBUG_PROCESS
4414  "xsltCopyOf: select %s\n", comp->select));
4415 #endif
4416 
4417  /*
4418  * Evaluate the "select" expression.
4419  */
4420  res = xsltPreCompEval(ctxt, node, comp);
4421 
4422  if (res != NULL) {
4423  if (res->type == XPATH_NODESET) {
4424  /*
4425  * Node-set
4426  * --------
4427  */
4428 #ifdef WITH_XSLT_DEBUG_PROCESS
4430  "xsltCopyOf: result is a node set\n"));
4431 #endif
4432  list = res->nodesetval;
4433  if (list != NULL) {
4434  xmlNodePtr cur;
4435  /*
4436  * The list is already sorted in document order by XPath.
4437  * Append everything in this order under ctxt->insert.
4438  */
4439  for (i = 0;i < list->nodeNr;i++) {
4440  cur = list->nodeTab[i];
4441  if (cur == NULL)
4442  continue;
4443  if ((cur->type == XML_DOCUMENT_NODE) ||
4444  (cur->type == XML_HTML_DOCUMENT_NODE))
4445  {
4446  xsltCopyTreeList(ctxt, inst,
4447  cur->children, ctxt->insert, 0, 0);
4448  } else if (cur->type == XML_ATTRIBUTE_NODE) {
4449  xsltShallowCopyAttr(ctxt, inst,
4450  ctxt->insert, (xmlAttrPtr) cur);
4451  } else {
4452  xsltCopyTree(ctxt, inst, cur, ctxt->insert, 0, 0);
4453  }
4454  }
4455  }
4456  } else if (res->type == XPATH_XSLT_TREE) {
4457  /*
4458  * Result tree fragment
4459  * --------------------
4460  * E.g. via <xsl:variable ...><foo/></xsl:variable>
4461  * Note that the root node of such trees is an xmlDocPtr in Libxslt.
4462  */
4463 #ifdef WITH_XSLT_DEBUG_PROCESS
4465  "xsltCopyOf: result is a result tree fragment\n"));
4466 #endif
4467  list = res->nodesetval;
4468  if ((list != NULL) && (list->nodeTab != NULL) &&
4469  (list->nodeTab[0] != NULL) &&
4470  (IS_XSLT_REAL_NODE(list->nodeTab[0])))
4471  {
4472  xsltCopyTreeList(ctxt, inst,
4473  list->nodeTab[0]->children, ctxt->insert, 0, 0);
4474  }
4475  } else {
4476  xmlChar *value = NULL;
4477  /*
4478  * Convert to a string.
4479  */
4480  value = xmlXPathCastToString(res);
4481  if (value == NULL) {
4482  xsltTransformError(ctxt, NULL, inst,
4483  "Internal error in xsltCopyOf(): "
4484  "failed to cast an XPath object to string.\n");
4485  ctxt->state = XSLT_STATE_STOPPED;
4486  } else {
4487  if (value[0] != 0) {
4488  /*
4489  * Append content as text node.
4490  */
4491  xsltCopyTextString(ctxt, ctxt->insert, value, 0);
4492  }
4493  xmlFree(value);
4494 
4495 #ifdef WITH_XSLT_DEBUG_PROCESS
4497  "xsltCopyOf: result %s\n", res->stringval));
4498 #endif
4499  }
4500  }
4501  } else {
4502  ctxt->state = XSLT_STATE_STOPPED;
4503  }
4504 
4505  if (res != NULL)
4506  xmlXPathFreeObject(res);
4507 }
static xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr node, xmlNodePtr insert, int isLRE, int topElemVisited)
Definition: transform.c:1593
xsltTransformState state
static xmlAttrPtr xsltShallowCopyAttr(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr target, xmlAttrPtr attr)
Definition: transform.c:1122
xmlNodePtr xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int noescape)
Definition: transform.c:850
static xmlXPathObjectPtr xsltPreCompEval(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:321
void * xsltGenericDebugContext
Definition: xsltutils.c:549
#define IS_XSLT_REAL_NODE(n)
Definition: xsltutils.h:71
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
unsigned char xmlChar
Definition: xmlstring.h:28
Definition: _list.h:228
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
FxCollectionEntry * cur
xsltStylePreComp * xsltStylePreCompPtr
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
xmlXPathCompExprPtr comp
#define NULL
Definition: types.h:112
const xmlChar * select
Definition: tree.h:434
GLuint res
Definition: glext.h:9613
static xmlNodePtr xsltCopyTreeList(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr list, xmlNodePtr insert, int isLRE, int topElemVisited)
Definition: transform.c:1389
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
Definition: dlist.c:348

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopyText()

static xmlNodePtr xsltCopyText ( xsltTransformContextPtr  ctxt,
xmlNodePtr  target,
xmlNodePtr  cur,
int  interned 
)
static

xsltCopyText: @ctxt: a XSLT process context @target: the element where the text will be attached @cur: the text or CDATA node @interned: the string is in the target doc dictionary

Copy the text content of @cur and append it to @target's children.

Returns: the text node, where the text content of @cur is copied to. NULL in case of API or internal errors.

Definition at line 946 of file transform.c.

948 {
950 
951  if ((cur->type != XML_TEXT_NODE) &&
952  (cur->type != XML_CDATA_SECTION_NODE))
953  return(NULL);
954  if (cur->content == NULL)
955  return(NULL);
956 
957 #ifdef WITH_XSLT_DEBUG_PROCESS
958  if (cur->type == XML_CDATA_SECTION_NODE) {
960  "xsltCopyText: copy CDATA text %s\n",
961  cur->content));
962  } else if (cur->name == xmlStringTextNoenc) {
964  "xsltCopyText: copy unescaped text %s\n",
965  cur->content));
966  } else {
968  "xsltCopyText: copy text %s\n",
969  cur->content));
970  }
971 #endif
972 
973  /*
974  * Play save and reset the merging mechanism for every new
975  * target node.
976  */
977  if ((target == NULL) || (target->children == NULL)) {
978  ctxt->lasttext = NULL;
979  }
980 
981  if ((ctxt->style->cdataSection != NULL) &&
982  (ctxt->type == XSLT_OUTPUT_XML) &&
983  (target != NULL) &&
984  (target->type == XML_ELEMENT_NODE) &&
985  (((target->ns == NULL) &&
987  target->name, NULL) != NULL)) ||
988  ((target->ns != NULL) &&
990  target->name, target->ns->href) != NULL))))
991  {
992  /*
993  * Process "cdata-section-elements".
994  */
995  /*
996  * OPTIMIZE TODO: xsltCopyText() is also used for attribute content.
997  */
998  /*
999  * TODO: Since this doesn't merge adjacent CDATA-section nodes,
1000  * we'll get: <![CDATA[x]]><!CDATA[y]]>.
1001  * TODO: Reported in #321505.
1002  */
1003  if ((target->last != NULL) &&
1004  (target->last->type == XML_CDATA_SECTION_NODE))
1005  {
1006  /*
1007  * Append to existing CDATA-section node.
1008  */
1009  copy = xsltAddTextString(ctxt, target->last, cur->content,
1010  xmlStrlen(cur->content));
1011  goto exit;
1012  } else {
1013  unsigned int len;
1014 
1015  len = xmlStrlen(cur->content);
1016  copy = xmlNewCDataBlock(ctxt->output, cur->content, len);
1017  if (copy == NULL)
1018  goto exit;
1019  ctxt->lasttext = copy->content;
1020  ctxt->lasttsize = len;
1021  ctxt->lasttuse = len;
1022  }
1023  } else if ((target != NULL) &&
1024  (target->last != NULL) &&
1025  /* both escaped or both non-escaped text-nodes */
1026  (((target->last->type == XML_TEXT_NODE) &&
1027  (target->last->name == cur->name)) ||
1028  /* non-escaped text nodes and CDATA-section nodes */
1029  (((target->last->type == XML_CDATA_SECTION_NODE) &&
1030  (cur->name == xmlStringTextNoenc)))))
1031  {
1032  /*
1033  * we are appending to an existing text node
1034  */
1035  copy = xsltAddTextString(ctxt, target->last, cur->content,
1036  xmlStrlen(cur->content));
1037  goto exit;
1038  } else if ((interned) && (target != NULL) &&
1039  (target->doc != NULL) &&
1040  (target->doc->dict == ctxt->dict))
1041  {
1042  /*
1043  * TODO: DO we want to use this also for "text" output?
1044  */
1045  copy = xmlNewTextLen(NULL, 0);
1046  if (copy == NULL)
1047  goto exit;
1048  if (cur->name == xmlStringTextNoenc)
1049  copy->name = xmlStringTextNoenc;
1050 
1051  /*
1052  * Must confirm that content is in dict (bug 302821)
1053  * TODO: This check should be not needed for text coming
1054  * from the stylesheets
1055  */
1056  if (xmlDictOwns(ctxt->dict, cur->content))
1057  copy->content = cur->content;
1058  else {
1059  if ((copy->content = xmlStrdup(cur->content)) == NULL)
1060  return NULL;
1061  }
1062 
1063  ctxt->lasttext = NULL;
1064  } else {
1065  /*
1066  * normal processing. keep counters to extend the text node
1067  * in xsltAddTextString if needed.
1068  */
1069  unsigned int len;
1070 
1071  len = xmlStrlen(cur->content);
1072  copy = xmlNewTextLen(cur->content, len);
1073  if (copy == NULL)
1074  goto exit;
1075  if (cur->name == xmlStringTextNoenc)
1076  copy->name = xmlStringTextNoenc;
1077  ctxt->lasttext = copy->content;
1078  ctxt->lasttsize = len;
1079  ctxt->lasttuse = len;
1080  }
1081  if (copy != NULL) {
1082  if (target != NULL) {
1083  copy->doc = target->doc;
1084  /*
1085  * MAYBE TODO: Maybe we should reset the ctxt->lasttext here
1086  * to ensure that the optimized text-merging mechanism
1087  * won't interfere with normal node-merging in any case.
1088  */
1090  }
1091  } else {
1093  "xsltCopyText: text copy failed\n");
1094  }
1095 
1096 exit:
1097  if ((copy == NULL) || (copy->content == NULL)) {
1099  "Internal error in xsltCopyText(): "
1100  "Failed to copy the string.\n");
1101  ctxt->state = XSLT_STATE_STOPPED;
1102  }
1103  return(copy);
1104 }
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:752
XMLPUBFUN xmlNodePtr XMLCALL xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len)
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:481
xsltTransformState state
void * xsltGenericDebugContext
Definition: xsltutils.c:549
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
xmlHashTablePtr cdataSection
const xmlChar * lasttext
GLenum GLsizei len
Definition: glext.h:6722
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
FxCollectionEntry * cur
xsltStylesheetPtr style
static xmlNodePtr xsltAddTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int len)
Definition: transform.c:778
XMLPUBFUN int XMLCALL xmlDictOwns(xmlDictPtr dict, const xmlChar *str)
Definition: dict.c:1218
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
XMLPUBVAR const xmlChar xmlStringTextNoenc[]
#define NULL
Definition: types.h:112
GLenum target
Definition: glext.h:7315
void exit(int exitcode)
Definition: _exit.c:33
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
XMLPUBFUN xmlNodePtr XMLCALL xmlNewTextLen(const xmlChar *content, int len)
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66

Referenced by xsltApplySequenceConstructor(), xsltCopy(), xsltDefaultProcessOneNode(), and xsltShallowCopyElem().

◆ xsltCopyTextString()

xmlNodePtr xsltCopyTextString ( xsltTransformContextPtr  ctxt,
xmlNodePtr  target,
const xmlChar string,
int  noescape 
)

xsltCopyTextString: @ctxt: a XSLT process context @target: the element where the text will be attached @string: the text string @noescape: should disable-escaping be activated for this text node.

Adds @string to a newly created or an existent text node child of @target.

Returns: the text node, where the text content of @cur is copied to. NULL in case of API or internal errors.

Definition at line 850 of file transform.c.

852 {
854  int len;
855 
856  if (string == NULL)
857  return(NULL);
858 
859 #ifdef WITH_XSLT_DEBUG_PROCESS
861  "xsltCopyTextString: copy text %s\n",
862  string));
863 #endif
864 
865  /*
866  * Play safe and reset the merging mechanism for every new
867  * target node.
868  */
869  if ((target == NULL) || (target->children == NULL)) {
870  ctxt->lasttext = NULL;
871  }
872 
873  /* handle coalescing of text nodes here */
874  len = xmlStrlen(string);
875  if ((ctxt->type == XSLT_OUTPUT_XML) &&
876  (ctxt->style->cdataSection != NULL) &&
877  (target != NULL) &&
878  (target->type == XML_ELEMENT_NODE) &&
879  (((target->ns == NULL) &&
881  target->name, NULL) != NULL)) ||
882  ((target->ns != NULL) &&
884  target->name, target->ns->href) != NULL))))
885  {
886  /*
887  * Process "cdata-section-elements".
888  */
889  if ((target->last != NULL) &&
890  (target->last->type == XML_CDATA_SECTION_NODE))
891  {
892  return(xsltAddTextString(ctxt, target->last, string, len));
893  }
894  copy = xmlNewCDataBlock(ctxt->output, string, len);
895  } else if (noescape) {
896  /*
897  * Process "disable-output-escaping".
898  */
899  if ((target != NULL) && (target->last != NULL) &&
900  (target->last->type == XML_TEXT_NODE) &&
901  (target->last->name == xmlStringTextNoenc))
902  {
903  return(xsltAddTextString(ctxt, target->last, string, len));
904  }
905  copy = xmlNewTextLen(string, len);
906  if (copy != NULL)
907  copy->name = xmlStringTextNoenc;
908  } else {
909  /*
910  * Default processing.
911  */
912  if ((target != NULL) && (target->last != NULL) &&
913  (target->last->type == XML_TEXT_NODE) &&
914  (target->last->name == xmlStringText)) {
915  return(xsltAddTextString(ctxt, target->last, string, len));
916  }
917  copy = xmlNewTextLen(string, len);
918  }
919  if (copy != NULL && target != NULL)
921  if (copy != NULL) {
922  ctxt->lasttext = copy->content;
923  ctxt->lasttsize = len;
924  ctxt->lasttuse = len;
925  } else {
927  "xsltCopyTextString: text copy failed\n");
928  ctxt->lasttext = NULL;
929  }
930  return(copy);
931 }
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:752
XMLPUBFUN xmlNodePtr XMLCALL xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len)
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:481
XMLPUBVAR const xmlChar xmlStringText[]
void * xsltGenericDebugContext
Definition: xsltutils.c:549
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
Definition: tree.h:489
xmlHashTablePtr cdataSection
const xmlChar * lasttext
GLenum GLsizei len
Definition: glext.h:6722
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:128
xsltStylesheetPtr style
static xmlNodePtr xsltAddTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int len)
Definition: transform.c:778
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
XMLPUBVAR const xmlChar xmlStringTextNoenc[]
#define NULL
Definition: types.h:112
GLenum target
Definition: glext.h:7315
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
XMLPUBFUN xmlNodePtr XMLCALL xmlNewTextLen(const xmlChar *content, int len)

Referenced by xsltCopyOf(), xsltCopyTree(),