ReactOS 0.4.15-dev-7089-gea8a49d
transform.h File Reference
#include <libxml/parser.h>
#include <libxml/xmlIO.h>
#include "xsltexports.h"
#include <libxslt/xsltInternals.h>
Include dependency graph for transform.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

XSLTPUBFUN void XSLTCALL xsltSetXIncludeDefault (int xinclude)
 
XSLTPUBFUN int XSLTCALL xsltGetXIncludeDefault (void)
 
XSLTPUBFUN xsltTransformContextPtr XSLTCALL xsltNewTransformContext (xsltStylesheetPtr style, xmlDocPtr doc)
 
XSLTPUBFUN void XSLTCALL xsltFreeTransformContext (xsltTransformContextPtr ctxt)
 
XSLTPUBFUN xmlDocPtr XSLTCALL xsltApplyStylesheetUser (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
 
XSLTPUBFUN void XSLTCALL xsltProcessOneNode (xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStackElemPtr params)
 
XSLTPUBFUN void XSLTCALL xsltApplyStripSpaces (xsltTransformContextPtr ctxt, xmlNodePtr node)
 
XSLTPUBFUN xmlDocPtr XSLTCALL xsltApplyStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params)
 
XSLTPUBFUN xmlDocPtr XSLTCALL xsltProfileStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, FILE *output)
 
XSLTPUBFUN int XSLTCALL xsltRunStylesheet (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf)
 
XSLTPUBFUN int XSLTCALL xsltRunStylesheetUser (xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf, FILE *profile, xsltTransformContextPtr userCtxt)
 
XSLTPUBFUN void XSLTCALL xsltApplyOneTemplate (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr list, xsltTemplatePtr templ, xsltStackElemPtr params)
 
XSLTPUBFUN void XSLTCALL xsltDocumentElem (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltSort (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltCopy (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltText (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltElement (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltComment (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltAttribute (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltProcessingInstruction (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltCopyOf (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltValueOf (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltNumber (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltApplyImports (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltCallTemplate (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltApplyTemplates (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltChoose (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltIf (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltForEach (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp)
 
XSLTPUBFUN void XSLTCALL xsltRegisterAllElement (xsltTransformContextPtr ctxt)
 
XSLTPUBFUN xmlNodePtr XSLTCALL xsltCopyTextString (xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int noescape)
 
XSLTPUBFUN void XSLTCALL xsltLocalVariablePop (xsltTransformContextPtr ctxt, int limitNr, int level)
 
XSLTPUBFUN int XSLTCALL xsltLocalVariablePush (xsltTransformContextPtr ctxt, xsltStackElemPtr variable, int level)
 
XSLTPUBFUN void XSLTCALL xslHandleDebugger (xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
 

Function Documentation

◆ xslHandleDebugger()

◆ xsltApplyImports()

XSLTPUBFUN void XSLTCALL 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 4610 of file transform.c.

4613{
4614 xsltTemplatePtr templ;
4615
4616 if ((ctxt == NULL) || (inst == NULL))
4617 return;
4618
4619 if (comp == NULL) {
4620 xsltTransformError(ctxt, NULL, inst,
4621 "Internal error in xsltApplyImports(): "
4622 "The XSLT 'apply-imports' instruction was not compiled.\n");
4623 return;
4624 }
4625 /*
4626 * NOTE that ctxt->currentTemplateRule and ctxt->templ is not the
4627 * same; the former is the "Current Template Rule" as defined by the
4628 * XSLT spec, the latter is simply the template struct being
4629 * currently processed.
4630 */
4631 if (ctxt->currentTemplateRule == NULL) {
4632 /*
4633 * SPEC XSLT 2.0:
4634 * "[ERR XTDE0560] It is a non-recoverable dynamic error if
4635 * xsl:apply-imports or xsl:next-match is evaluated when the
4636 * current template rule is null."
4637 */
4638 xsltTransformError(ctxt, NULL, inst,
4639 "It is an error to call 'apply-imports' "
4640 "when there's no current template rule.\n");
4641 return;
4642 }
4643 /*
4644 * TODO: Check if this is correct.
4645 */
4646 templ = xsltGetTemplate(ctxt, contextNode,
4647 ctxt->currentTemplateRule->style);
4648
4649 if (templ != NULL) {
4650 xsltTemplatePtr oldCurTemplRule = ctxt->currentTemplateRule;
4651 /*
4652 * Set the current template rule.
4653 */
4654 ctxt->currentTemplateRule = templ;
4655 /*
4656 * URGENT TODO: Need xsl:with-param be handled somehow here?
4657 */
4658 xsltApplyXSLTTemplate(ctxt, contextNode, templ->content,
4659 templ, NULL);
4660
4661 ctxt->currentTemplateRule = oldCurTemplRule;
4662 }
4663 else {
4664 /* Use built-in templates. */
4665 xsltDefaultProcessOneNode(ctxt, contextNode, NULL);
4666 }
4667}
#define NULL
Definition: types.h:112
xsltTemplatePtr xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylesheetPtr style)
Definition: pattern.c:2259
static void xsltApplyXSLTTemplate(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ, xsltStackElemPtr withParams)
Definition: transform.c:3026
static void xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStackElemPtr params)
Definition: transform.c:1859
xmlNodePtr content
struct _xsltStylesheet * style
xsltTemplatePtr currentTemplateRule
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltApplyOneTemplate()

XSLTPUBFUN void XSLTCALL 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 3273 of file transform.c.

3278{
3279 if ((ctxt == NULL) || (list == NULL))
3280 return;
3282
3283 if (params) {
3284 /*
3285 * This code should be obsolete - was previously used
3286 * by libexslt/functions.c, but due to bug 381319 the
3287 * logic there was changed.
3288 */
3289 int oldVarsNr = ctxt->varsNr;
3290
3291 /*
3292 * Push the given xsl:param(s) onto the variable stack.
3293 */
3294 while (params != NULL) {
3295 xsltLocalVariablePush(ctxt, params, -1);
3296 params = params->next;
3297 }
3298 xsltApplySequenceConstructor(ctxt, contextNode, list, templ);
3299 /*
3300 * Pop the given xsl:param(s) from the stack but don't free them.
3301 */
3302 xsltLocalVariablePop(ctxt, oldVarsNr, -2);
3303 } else
3304 xsltApplySequenceConstructor(ctxt, contextNode, list, templ);
3305}
Definition: list.h:37
void xsltLocalVariablePop(xsltTransformContextPtr ctxt, int limitNr, int level)
Definition: transform.c:150
int xsltLocalVariablePush(xsltTransformContextPtr ctxt, xsltStackElemPtr variable, int level)
Definition: transform.c:2188
static void xsltApplySequenceConstructor(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr list, xsltTemplatePtr templ)
Definition: transform.c:2278
GLenum const GLfloat * params
Definition: glext.h:5645
#define CHECK_STOPPED

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

◆ xsltApplyStripSpaces()

XSLTPUBFUN void XSLTCALL xsltApplyStripSpaces ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node 
)

Private Interfaces.

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 5609 of file transform.c.

5609 {
5611#ifdef WITH_XSLT_DEBUG_PROCESS
5612 int nb = 0;
5613#endif
5614
5615
5616 current = node;
5617 while (current != NULL) {
5618 /*
5619 * Cleanup children empty nodes if asked for
5620 */
5621 if ((IS_XSLT_REAL_NODE(current)) &&
5622 (current->children != NULL) &&
5624 xmlNodePtr delete = NULL, cur = current->children;
5625
5626 while (cur != NULL) {
5627 if (IS_BLANK_NODE(cur))
5628 delete = cur;
5629
5630 cur = cur->next;
5631 if (delete != NULL) {
5632 xmlUnlinkNode(delete);
5633 xmlFreeNode(delete);
5634 delete = NULL;
5635#ifdef WITH_XSLT_DEBUG_PROCESS
5636 nb++;
5637#endif
5638 }
5639 }
5640 }
5641
5642 /*
5643 * Skip to next node in document order.
5644 */
5645 if (node->type == XML_ENTITY_REF_NODE) {
5646 /* process deep in entities */
5647 xsltApplyStripSpaces(ctxt, node->children);
5648 }
5649 if ((current->children != NULL) &&
5650 (current->type != XML_ENTITY_REF_NODE)) {
5651 current = current->children;
5652 } else if (current->next != NULL) {
5653 current = current->next;
5654 } else {
5655 do {
5656 current = current->parent;
5657 if (current == NULL)
5658 break;
5659 if (current == node)
5660 goto done;
5661 if (current->next != NULL) {
5662 current = current->next;
5663 break;
5664 }
5665 } while (current != NULL);
5666 }
5667 }
5668
5669done:
5670#ifdef WITH_XSLT_DEBUG_PROCESS
5672 "xsltApplyStripSpaces: removed %d ignorable blank node\n", nb));
5673#endif
5674 return;
5675}
#define IS_BLANK_NODE(n)
Definition: transform.c:47
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5609
FxCollectionEntry * cur
int xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: imports.c:303
struct task_struct * current
Definition: linux.c:32
@ XML_ENTITY_REF_NODE
Definition: tree.h:164
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
Definition: tree.h:489
Definition: dlist.c:348
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
void * xsltGenericDebugContext
Definition: xsltutils.c:549
@ XSLT_TRACE_STRIP_SPACES
Definition: xsltutils.h:114
#define IS_XSLT_REAL_NODE(n)
Definition: xsltutils.h:68
#define XSLT_TRACE(ctxt, code, call)
Definition: xsltutils.h:125

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

◆ xsltApplyStylesheet()

XSLTPUBFUN xmlDocPtr XSLTCALL 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 6144 of file transform.c.

6146{
6148}
Arabic default style
Definition: afstyles.h:94
static xmlDocPtr xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, FILE *profile, xsltTransformContextPtr userCtxt)
Definition: transform.c:5729

◆ xsltApplyStylesheetUser()

XSLTPUBFUN xmlDocPtr XSLTCALL 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 6187 of file transform.c.

6190{
6191 xmlDocPtr res;
6192
6194 profile, userCtxt);
6195 return (res);
6196}
GLuint res
Definition: glext.h:9613
#define profile
Definition: kernel32.h:12
Definition: tree.h:551

◆ xsltApplyTemplates()

XSLTPUBFUN void XSLTCALL 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 4782 of file transform.c.

4784{
4785#ifdef XSLT_REFACTORED
4786 xsltStyleItemApplyTemplatesPtr comp =
4787 (xsltStyleItemApplyTemplatesPtr) castedComp;
4788#else
4789 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4790#endif
4791 int i;
4792 xmlNodePtr cur, oldContextNode;
4793 xmlNodeSetPtr list = NULL, oldList;
4794 xsltStackElemPtr withParams = NULL;
4795 int oldXPProximityPosition, oldXPContextSize;
4796 const xmlChar *oldMode, *oldModeURI;
4797 xmlDocPtr oldXPDoc;
4798 xsltDocumentPtr oldDocInfo;
4799 xmlXPathContextPtr xpctxt;
4800
4801 if (comp == NULL) {
4802 xsltTransformError(ctxt, NULL, inst,
4803 "xsl:apply-templates : compilation failed\n");
4804 return;
4805 }
4806 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
4807 return;
4808
4809#ifdef WITH_XSLT_DEBUG_PROCESS
4810 if ((node != NULL) && (node->name != NULL))
4812 "xsltApplyTemplates: node: '%s'\n", node->name));
4813#endif
4814
4815 xpctxt = ctxt->xpathCtxt;
4816 /*
4817 * Save context states.
4818 */
4819 oldContextNode = ctxt->node;
4820 oldMode = ctxt->mode;
4821 oldModeURI = ctxt->modeURI;
4822 oldDocInfo = ctxt->document;
4823 oldList = ctxt->nodeList;
4824
4825 /*
4826 * The xpath context size and proximity position, as
4827 * well as the xpath and context documents, may be changed
4828 * so we save their initial state and will restore on exit
4829 */
4830 oldXPContextSize = xpctxt->contextSize;
4831 oldXPProximityPosition = xpctxt->proximityPosition;
4832 oldXPDoc = xpctxt->doc;
4833
4834 /*
4835 * Set up contexts.
4836 */
4837 ctxt->mode = comp->mode;
4838 ctxt->modeURI = comp->modeURI;
4839
4840 if (comp->select != NULL) {
4841 xmlXPathObjectPtr res = NULL;
4842
4843 if (comp->comp == NULL) {
4844 xsltTransformError(ctxt, NULL, inst,
4845 "xsl:apply-templates : compilation failed\n");
4846 goto error;
4847 }
4848#ifdef WITH_XSLT_DEBUG_PROCESS
4850 "xsltApplyTemplates: select %s\n", comp->select));
4851#endif
4852
4853 res = xsltPreCompEval(ctxt, node, comp);
4854
4855 if (res != NULL) {
4856 if (res->type == XPATH_NODESET) {
4857 list = res->nodesetval; /* consume the node set */
4858 res->nodesetval = NULL;
4859 } else {
4860 xsltTransformError(ctxt, NULL, inst,
4861 "The 'select' expression did not evaluate to a "
4862 "node set.\n");
4863 ctxt->state = XSLT_STATE_STOPPED;
4864 xmlXPathFreeObject(res);
4865 goto error;
4866 }
4867 xmlXPathFreeObject(res);
4868 /*
4869 * Note: An xsl:apply-templates with a 'select' attribute,
4870 * can change the current source doc.
4871 */
4872 } else {
4873 xsltTransformError(ctxt, NULL, inst,
4874 "Failed to evaluate the 'select' expression.\n");
4875 ctxt->state = XSLT_STATE_STOPPED;
4876 goto error;
4877 }
4878 if (list == NULL) {
4879#ifdef WITH_XSLT_DEBUG_PROCESS
4881 "xsltApplyTemplates: select didn't evaluate to a node list\n"));
4882#endif
4883 goto exit;
4884 }
4885 /*
4886 *
4887 * NOTE: Previously a document info (xsltDocument) was
4888 * created and attached to the Result Tree Fragment.
4889 * But such a document info is created on demand in
4890 * xsltKeyFunction() (functions.c), so we need to create
4891 * it here beforehand.
4892 * In order to take care of potential keys we need to
4893 * do some extra work for the case when a Result Tree Fragment
4894 * is converted into a nodeset (e.g. exslt:node-set()) :
4895 * We attach a "pseudo-doc" (xsltDocument) to _private.
4896 * This xsltDocument, together with the keyset, will be freed
4897 * when the Result Tree Fragment is freed.
4898 *
4899 */
4900#if 0
4901 if ((ctxt->nbKeys > 0) &&
4902 (list->nodeNr != 0) &&
4903 (list->nodeTab[0]->doc != NULL) &&
4904 XSLT_IS_RES_TREE_FRAG(list->nodeTab[0]->doc))
4905 {
4906 /*
4907 * NOTE that it's also OK if @effectiveDocInfo will be
4908 * set to NULL.
4909 */
4910 isRTF = 1;
4911 effectiveDocInfo = list->nodeTab[0]->doc->_private;
4912 }
4913#endif
4914 } else {
4915 /*
4916 * Build an XPath node set with the children
4917 */
4918 list = xmlXPathNodeSetCreate(NULL);
4919 if (list == NULL)
4920 goto error;
4921 if (node->type != XML_NAMESPACE_DECL)
4922 cur = node->children;
4923 else
4924 cur = NULL;
4925 while (cur != NULL) {
4927 xmlXPathNodeSetAddUnique(list, cur);
4928 cur = cur->next;
4929 }
4930 }
4931
4932#ifdef WITH_XSLT_DEBUG_PROCESS
4933 if (list != NULL)
4935 "xsltApplyTemplates: list of %d nodes\n", list->nodeNr));
4936#endif
4937
4938 if ((list == NULL) || (list->nodeNr == 0))
4939 goto exit;
4940
4941 /*
4942 * Set the context's node set and size; this is also needed for
4943 * for xsltDoSortFunction().
4944 */
4945 ctxt->nodeList = list;
4946 /*
4947 * Process xsl:with-param and xsl:sort instructions.
4948 * (The code became so verbose just to avoid the
4949 * xmlNodePtr sorts[XSLT_MAX_SORT] if there's no xsl:sort)
4950 * BUG TODO: We are not using namespaced potentially defined on the
4951 * xsl:sort or xsl:with-param elements; XPath expression might fail.
4952 */
4953 if (inst->children) {
4955
4956 cur = inst->children;
4957 while (cur) {
4958
4959#ifdef WITH_DEBUGGER
4960 if (ctxt->debugStatus != XSLT_DEBUG_NONE)
4961 xslHandleDebugger(cur, node, NULL, ctxt);
4962#endif
4963 if (ctxt->state == XSLT_STATE_STOPPED)
4964 break;
4965 if (cur->type == XML_TEXT_NODE) {
4966 cur = cur->next;
4967 continue;
4968 }
4969 if (! IS_XSLT_ELEM(cur))
4970 break;
4971 if (IS_XSLT_NAME(cur, "with-param")) {
4973 if (param != NULL) {
4974 param->next = withParams;
4975 withParams = param;
4976 }
4977 }
4978 if (IS_XSLT_NAME(cur, "sort")) {
4979 xsltTemplatePtr oldCurTempRule =
4980 ctxt->currentTemplateRule;
4981 int nbsorts = 0;
4983
4984 sorts[nbsorts++] = cur;
4985 cur = cur->next;
4986
4987 while (cur) {
4988
4989#ifdef WITH_DEBUGGER
4990 if (ctxt->debugStatus != XSLT_DEBUG_NONE)
4991 xslHandleDebugger(cur, node, NULL, ctxt);
4992#endif
4993 if (ctxt->state == XSLT_STATE_STOPPED)
4994 break;
4995
4996 if (cur->type == XML_TEXT_NODE) {
4997 cur = cur->next;
4998 continue;
4999 }
5000
5001 if (! IS_XSLT_ELEM(cur))
5002 break;
5003 if (IS_XSLT_NAME(cur, "with-param")) {
5005 if (param != NULL) {
5006 param->next = withParams;
5007 withParams = param;
5008 }
5009 }
5010 if (IS_XSLT_NAME(cur, "sort")) {
5011 if (nbsorts >= XSLT_MAX_SORT) {
5013 "The number (%d) of xsl:sort instructions exceeds the "
5014 "maximum allowed by this processor's settings.\n",
5015 nbsorts);
5016 ctxt->state = XSLT_STATE_STOPPED;
5017 break;
5018 } else {
5019 sorts[nbsorts++] = cur;
5020 }
5021 }
5022 cur = cur->next;
5023 }
5024 /*
5025 * The "current template rule" is cleared for xsl:sort.
5026 */
5027 ctxt->currentTemplateRule = NULL;
5028 /*
5029 * Sort.
5030 */
5031 xsltDoSortFunction(ctxt, sorts, nbsorts);
5032 ctxt->currentTemplateRule = oldCurTempRule;
5033 break;
5034 }
5035 cur = cur->next;
5036 }
5037 }
5038 xpctxt->contextSize = list->nodeNr;
5039 /*
5040 * Apply templates for all selected source nodes.
5041 */
5042 for (i = 0; i < list->nodeNr; i++) {
5043 cur = list->nodeTab[i];
5044 /*
5045 * The node becomes the "current node".
5046 */
5047 ctxt->node = cur;
5048 /*
5049 * An xsl:apply-templates can change the current context doc.
5050 * OPTIMIZE TODO: Get rid of the need to set the context doc.
5051 */
5052 if ((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL))
5053 xpctxt->doc = cur->doc;
5054
5055 xpctxt->proximityPosition = i + 1;
5056 /*
5057 * Find and apply a template for this node.
5058 */
5059 xsltProcessOneNode(ctxt, cur, withParams);
5060 }
5061
5062exit:
5063error:
5064 /*
5065 * Free the parameter list.
5066 */
5067 if (withParams != NULL)
5068 xsltFreeStackElemList(withParams);
5069 if (list != NULL)
5070 xmlXPathFreeNodeSet(list);
5071 /*
5072 * Restore context states.
5073 */
5074 xpctxt->doc = oldXPDoc;
5075 xpctxt->contextSize = oldXPContextSize;
5076 xpctxt->proximityPosition = oldXPProximityPosition;
5077
5078 ctxt->document = oldDocInfo;
5079 ctxt->nodeList = oldList;
5080 ctxt->node = oldContextNode;
5081 ctxt->mode = oldMode;
5082 ctxt->modeURI = oldModeURI;
5083}
static xmlXPathObjectPtr xsltPreCompEval(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:321
void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xsltStackElemPtr withParams)
Definition: transform.c:2064
GLfloat param
Definition: glext.h:5796
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 error(str)
Definition: mkdosfs.c:1605
#define list
Definition: rosglue.h:35
@ XML_TEXT_NODE
Definition: tree.h:162
@ XML_NAMESPACE_DECL
Definition: tree.h:177
#define exit(n)
Definition: config.h:202
struct _xmlDoc * doc
Definition: tree.h:560
struct _xmlNode * children
Definition: tree.h:493
xsltTransformState state
const xmlChar * modeURI
xsltDocumentPtr document
xmlNodeSetPtr nodeList
xmlXPathContextPtr xpathCtxt
const xmlChar * mode
XSLTPUBFUN void XSLTCALL xslHandleDebugger(xmlNodePtr cur, xmlNodePtr node, xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
xsltStackElemPtr xsltParseStylesheetCallerParam(xsltTransformContextPtr ctxt, xmlNodePtr inst)
Definition: variables.c:1962
void xsltFreeStackElemList(xsltStackElemPtr elem)
Definition: variables.c:603
unsigned char xmlChar
Definition: xmlstring.h:28
@ XSLT_STATE_STOPPED
#define XSLT_MAX_SORT
#define XSLT_IS_RES_TREE_FRAG(n)
Definition: xsltInternals.h:56
xsltStylePreComp * xsltStylePreCompPtr
void xsltDoSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, int nbsorts)
Definition: xsltutils.c:1369
@ XSLT_DEBUG_NONE
Definition: xsltutils.h:273
#define IS_XSLT_NAME(n, val)
Definition: xsltutils.h:60
@ XSLT_TRACE_APPLY_TEMPLATES
Definition: xsltutils.h:110
#define IS_XSLT_ELEM(n)
Definition: xsltutils.h:51

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltAttribute()

XSLTPUBFUN void XSLTCALL xsltAttribute ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltAttribute: @ctxt: a XSLT process context @contextNode: the current node in the source tree @inst: the xsl:attribute element @castedComp: precomputed information

Process the xslt attribute node on the source node

Definition at line 716 of file attributes.c.

720{
721#ifdef XSLT_REFACTORED
722 xsltStyleItemAttributePtr comp =
723 (xsltStyleItemAttributePtr) castedComp;
724#else
725 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
726#endif
727 xmlNodePtr targetElem;
728 xmlChar *prop = NULL;
729 const xmlChar *name = NULL, *prefix = NULL, *nsName = NULL;
730 xmlChar *value = NULL;
731 xmlNsPtr ns = NULL;
733
734 if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL) ||
735 (inst->type != XML_ELEMENT_NODE) )
736 return;
737
738 /*
739 * A comp->has_name == 0 indicates that we need to skip this instruction,
740 * since it was evaluated to be invalid already during compilation.
741 */
742 if (!comp->has_name)
743 return;
744 /*
745 * BIG NOTE: This previously used xsltGetSpecialNamespace() and
746 * xsltGetNamespace(), but since both are not appropriate, we
747 * will process namespace lookup here to avoid adding yet another
748 * ns-lookup function to namespaces.c.
749 */
750 /*
751 * SPEC XSLT 1.0: Error cases:
752 * - Creating nodes other than text nodes during the instantiation of
753 * the content of the xsl:attribute element; implementations may
754 * either signal the error or ignore the offending nodes."
755 */
756
757 if (comp == NULL) {
758 xsltTransformError(ctxt, NULL, inst,
759 "Internal error in xsltAttribute(): "
760 "The XSLT 'attribute' instruction was not compiled.\n");
761 return;
762 }
763 /*
764 * TODO: Shouldn't ctxt->insert == NULL be treated as an internal error?
765 * So report an internal error?
766 */
767 if (ctxt->insert == NULL)
768 return;
769 /*
770 * SPEC XSLT 1.0:
771 * "Adding an attribute to a node that is not an element;
772 * implementations may either signal the error or ignore the attribute."
773 *
774 * TODO: I think we should signal such errors in the future, and maybe
775 * provide an option to ignore such errors.
776 */
777 targetElem = ctxt->insert;
778 if (targetElem->type != XML_ELEMENT_NODE)
779 return;
780
781 /*
782 * SPEC XSLT 1.0:
783 * "Adding an attribute to an element after children have been added
784 * to it; implementations may either signal the error or ignore the
785 * attribute."
786 *
787 * TODO: We should decide whether not to report such errors or
788 * to ignore them; note that we *ignore* if the parent is not an
789 * element, but here we report an error.
790 */
791 if (targetElem->children != NULL) {
792 /*
793 * NOTE: Ah! This seems to be intended to support streamed
794 * result generation!.
795 */
796 xsltTransformError(ctxt, NULL, inst,
797 "xsl:attribute: Cannot add attributes to an "
798 "element if children have been already added "
799 "to the element.\n");
800 return;
801 }
802
803 /*
804 * Process the name
805 * ----------------
806 */
807
808#ifdef WITH_DEBUGGER
809 if (ctxt->debugStatus != XSLT_DEBUG_NONE)
810 xslHandleDebugger(inst, contextNode, NULL, ctxt);
811#endif
812
813 if (comp->name == NULL) {
814 /* TODO: fix attr acquisition wrt to the XSLT namespace */
815 prop = xsltEvalAttrValueTemplate(ctxt, inst,
816 (const xmlChar *) "name", XSLT_NAMESPACE);
817 if (prop == NULL) {
818 xsltTransformError(ctxt, NULL, inst,
819 "xsl:attribute: The attribute 'name' is missing.\n");
820 goto error;
821 }
822 if (xmlValidateQName(prop, 0)) {
823 xsltTransformError(ctxt, NULL, inst,
824 "xsl:attribute: The effective name '%s' is not a "
825 "valid QName.\n", prop);
826 /* we fall through to catch any further errors, if possible */
827 }
828
829 /*
830 * Reject a name of "xmlns".
831 */
832 if (xmlStrEqual(prop, BAD_CAST "xmlns")) {
833 xsltTransformError(ctxt, NULL, inst,
834 "xsl:attribute: The effective name 'xmlns' is not allowed.\n");
835 xmlFree(prop);
836 goto error;
837 }
838
839 name = xsltSplitQName(ctxt->dict, prop, &prefix);
840 xmlFree(prop);
841 } else {
842 /*
843 * The "name" value was static.
844 */
845#ifdef XSLT_REFACTORED
846 prefix = comp->nsPrefix;
847 name = comp->name;
848#else
849 name = xsltSplitQName(ctxt->dict, comp->name, &prefix);
850#endif
851 }
852
853 /*
854 * Process namespace semantics
855 * ---------------------------
856 *
857 * Evaluate the namespace name.
858 */
859 if (comp->has_ns) {
860 /*
861 * The "namespace" attribute was existent.
862 */
863 if (comp->ns != NULL) {
864 /*
865 * No AVT; just plain text for the namespace name.
866 */
867 if (comp->ns[0] != 0)
868 nsName = comp->ns;
869 } else {
870 xmlChar *tmpNsName;
871 /*
872 * Eval the AVT.
873 */
874 /* TODO: check attr acquisition wrt to the XSLT namespace */
875 tmpNsName = xsltEvalAttrValueTemplate(ctxt, inst,
876 (const xmlChar *) "namespace", XSLT_NAMESPACE);
877 /*
878 * This fixes bug #302020: The AVT might also evaluate to the
879 * empty string; this means that the empty string also indicates
880 * "no namespace".
881 * SPEC XSLT 1.0:
882 * "If the string is empty, then the expanded-name of the
883 * attribute has a null namespace URI."
884 */
885 if ((tmpNsName != NULL) && (tmpNsName[0] != 0))
886 nsName = xmlDictLookup(ctxt->dict, BAD_CAST tmpNsName, -1);
887 xmlFree(tmpNsName);
888 }
889
890 if (xmlStrEqual(nsName, BAD_CAST "http://www.w3.org/2000/xmlns/")) {
891 xsltTransformError(ctxt, NULL, inst,
892 "xsl:attribute: Namespace http://www.w3.org/2000/xmlns/ "
893 "forbidden.\n");
894 goto error;
895 }
896 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
897 prefix = BAD_CAST "xml";
898 } else if (xmlStrEqual(prefix, BAD_CAST "xml")) {
899 prefix = NULL;
900 }
901 } else if (prefix != NULL) {
902 /*
903 * SPEC XSLT 1.0:
904 * "If the namespace attribute is not present, then the QName is
905 * expanded into an expanded-name using the namespace declarations
906 * in effect for the xsl:attribute element, *not* including any
907 * default namespace declaration."
908 */
909 ns = xmlSearchNs(inst->doc, inst, prefix);
910 if (ns == NULL) {
911 /*
912 * Note that this is treated as an error now (checked with
913 * Saxon, Xalan-J and MSXML).
914 */
915 xsltTransformError(ctxt, NULL, inst,
916 "xsl:attribute: The QName '%s:%s' has no "
917 "namespace binding in scope in the stylesheet; "
918 "this is an error, since the namespace was not "
919 "specified by the instruction itself.\n", prefix, name);
920 } else
921 nsName = ns->href;
922 }
923
924 /*
925 * Find/create a matching ns-decl in the result tree.
926 */
927 ns = NULL;
928
929#if 0
930 if (0) {
931 /*
932 * OPTIMIZE TODO: How do we know if we are adding to a
933 * fragment or to the result tree?
934 *
935 * If we are adding to a result tree fragment (i.e., not to the
936 * actual result tree), we'll don't bother searching for the
937 * ns-decl, but just store it in the dummy-doc of the result
938 * tree fragment.
939 */
940 if (nsName != NULL) {
941 /*
942 * TODO: Get the doc of @targetElem.
943 */
944 ns = xsltTreeAcquireStoredNs(some doc, nsName, prefix);
945 }
946 }
947#endif
948
949 if (nsName != NULL) {
950 /*
951 * Something about ns-prefixes:
952 * SPEC XSLT 1.0:
953 * "XSLT processors may make use of the prefix of the QName specified
954 * in the name attribute when selecting the prefix used for outputting
955 * the created attribute as XML; however, they are not required to do
956 * so and, if the prefix is xmlns, they must not do so"
957 */
958 /*
959 * xsl:attribute can produce a scenario where the prefix is NULL,
960 * so generate a prefix.
961 */
962 if ((prefix == NULL) || xmlStrEqual(prefix, BAD_CAST "xmlns")) {
963 xmlChar *pref = xmlStrdup(BAD_CAST "ns_1");
964
965 ns = xsltGetSpecialNamespace(ctxt, inst, nsName, pref, targetElem);
966
967 xmlFree(pref);
968 } else {
969 ns = xsltGetSpecialNamespace(ctxt, inst, nsName, prefix,
970 targetElem);
971 }
972 if (ns == NULL) {
973 xsltTransformError(ctxt, NULL, inst,
974 "Namespace fixup error: Failed to acquire an in-scope "
975 "namespace binding for the generated attribute '{%s}%s'.\n",
976 nsName, name);
977 goto error;
978 }
979 }
980 /*
981 * Construction of the value
982 * -------------------------
983 */
984 if (inst->children == NULL) {
985 /*
986 * No content.
987 * TODO: Do we need to put the empty string in ?
988 */
989 attr = xmlSetNsProp(ctxt->insert, ns, name, (const xmlChar *) "");
990 } else if ((inst->children->next == NULL) &&
991 ((inst->children->type == XML_TEXT_NODE) ||
992 (inst->children->type == XML_CDATA_SECTION_NODE)))
993 {
994 xmlNodePtr copyTxt;
995
996 /*
997 * xmlSetNsProp() will take care of duplicates.
998 */
999 attr = xmlSetNsProp(ctxt->insert, ns, name, NULL);
1000 if (attr == NULL) /* TODO: report error ? */
1001 goto error;
1002 /*
1003 * This was taken over from xsltCopyText() (transform.c).
1004 */
1005 if (ctxt->internalized &&
1006 (ctxt->insert->doc != NULL) &&
1007 (ctxt->insert->doc->dict == ctxt->dict))
1008 {
1009 copyTxt = xmlNewText(NULL);
1010 if (copyTxt == NULL) /* TODO: report error */
1011 goto error;
1012 /*
1013 * This is a safe scenario where we don't need to lookup
1014 * the dict.
1015 */
1016 copyTxt->content = inst->children->content;
1017 /*
1018 * Copy "disable-output-escaping" information.
1019 * TODO: Does this have any effect for attribute values
1020 * anyway?
1021 */
1022 if (inst->children->name == xmlStringTextNoenc)
1023 copyTxt->name = xmlStringTextNoenc;
1024 } else {
1025 /*
1026 * Copy the value.
1027 */
1028 copyTxt = xmlNewText(inst->children->content);
1029 if (copyTxt == NULL) /* TODO: report error */
1030 goto error;
1031 }
1032 attr->children = attr->last = copyTxt;
1033 copyTxt->parent = (xmlNodePtr) attr;
1034 copyTxt->doc = attr->doc;
1035 /*
1036 * Copy "disable-output-escaping" information.
1037 * TODO: Does this have any effect for attribute values
1038 * anyway?
1039 */
1040 if (inst->children->name == xmlStringTextNoenc)
1041 copyTxt->name = xmlStringTextNoenc;
1042
1043 /*
1044 * since we create the attribute without content IDness must be
1045 * asserted as a second step
1046 */
1047 if ((copyTxt->content != NULL) &&
1048 (xmlIsID(attr->doc, attr->parent, attr)))
1049 xmlAddID(NULL, attr->doc, copyTxt->content, attr);
1050 } else {
1051 /*
1052 * The sequence constructor might be complex, so instantiate it.
1053 */
1054 value = xsltEvalTemplateString(ctxt, contextNode, inst);
1055 if (value != NULL) {
1056 attr = xmlSetNsProp(ctxt->insert, ns, name, value);
1057 xmlFree(value);
1058 } else {
1059 /*
1060 * TODO: Do we have to add the empty string to the attr?
1061 * TODO: Does a value of NULL indicate an
1062 * error in xsltEvalTemplateString() ?
1063 */
1064 attr = xmlSetNsProp(ctxt->insert, ns, name,
1065 (const xmlChar *) "");
1066 }
1067 }
1068
1069error:
1070 return;
1071}
xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, const xmlChar *nsName, const xmlChar *nsPrefix, xmlNodePtr target)
Definition: namespaces.c:299
XMLPUBVAR const xmlChar xmlStringTextNoenc[]
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
Definition: dict.c:867
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
XMLPUBFUN xmlNsPtr XMLCALL xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace)
xmlNode * xmlNodePtr
Definition: tree.h:488
XMLPUBFUN xmlNodePtr XMLCALL xmlNewText(const xmlChar *content)
@ XML_CDATA_SECTION_NODE
Definition: tree.h:163
@ XML_ELEMENT_NODE
Definition: tree.h:160
#define XML_XML_NAMESPACE
Definition: tree.h:140
Definition: tree.h:434
xmlChar * content
Definition: tree.h:502
struct _xmlDoc * doc
Definition: tree.h:498
const xmlChar * name
Definition: tree.h:492
xmlElementType type
Definition: tree.h:491
struct _xmlNode * parent
Definition: tree.h:495
Definition: tree.h:389
Definition: cookie.c:202
Definition: name.c:39
WCHAR * name
Definition: name.c:42
Definition: mxnamespace.c:45
xmlChar * xsltEvalAttrValueTemplate(xsltTransformContextPtr ctxt, xmlNodePtr inst, const xmlChar *name, const xmlChar *ns)
Definition: templates.c:392
xmlChar * xsltEvalTemplateString(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst)
Definition: templates.c:189
Definition: pdh_main.c:94
XMLPUBFUN xmlIDPtr XMLCALL xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, xmlAttrPtr attr)
Definition: valid.c:2672
XMLPUBFUN int XMLCALL xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr)
Definition: valid.c:2774
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:160
#define XSLT_NAMESPACE
Definition: xslt.h:46
const xmlChar * xsltSplitQName(xmlDictPtr dict, const xmlChar *name, const xmlChar **prefix)
Definition: xsltutils.c:720

Referenced by xsltApplyAttributeSet(), xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCallTemplate()

XSLTPUBFUN void XSLTCALL 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 4679 of file transform.c.

4681{
4682#ifdef XSLT_REFACTORED
4683 xsltStyleItemCallTemplatePtr comp =
4684 (xsltStyleItemCallTemplatePtr) castedComp;
4685#else
4686 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4687#endif
4688 xsltStackElemPtr withParams = NULL;
4689
4690 if (ctxt->insert == NULL)
4691 return;
4692 if (comp == NULL) {
4693 xsltTransformError(ctxt, NULL, inst,
4694 "The XSLT 'call-template' instruction was not compiled.\n");
4695 return;
4696 }
4697
4698 /*
4699 * The template must have been precomputed
4700 */
4701 if (comp->templ == NULL) {
4702 comp->templ = xsltFindTemplate(ctxt, comp->name, comp->ns);
4703 if (comp->templ == NULL) {
4704 if (comp->ns != NULL) {
4705 xsltTransformError(ctxt, NULL, inst,
4706 "The called template '{%s}%s' was not found.\n",
4707 comp->ns, comp->name);
4708 } else {
4709 xsltTransformError(ctxt, NULL, inst,
4710 "The called template '%s' was not found.\n",
4711 comp->name);
4712 }
4713 return;
4714 }
4715 }
4716
4717#ifdef WITH_XSLT_DEBUG_PROCESS
4718 if ((comp != NULL) && (comp->name != NULL))
4720 "call-template: name %s\n", comp->name));
4721#endif
4722
4723 if (inst->children) {
4726
4727 cur = inst->children;
4728 while (cur != NULL) {
4729#ifdef WITH_DEBUGGER
4730 if (ctxt->debugStatus != XSLT_DEBUG_NONE)
4731 xslHandleDebugger(cur, node, comp->templ, ctxt);
4732#endif
4733 if (ctxt->state == XSLT_STATE_STOPPED) break;
4734 /*
4735 * TODO: The "with-param"s could be part of the "call-template"
4736 * structure. Avoid to "search" for params dynamically
4737 * in the XML tree every time.
4738 */
4739 if (IS_XSLT_ELEM(cur)) {
4740 if (IS_XSLT_NAME(cur, "with-param")) {
4742 if (param != NULL) {
4743 param->next = withParams;
4744 withParams = param;
4745 }
4746 } else {
4748 "xsl:call-template: misplaced xsl:%s\n", cur->name);
4749 }
4750 } else {
4752 "xsl:call-template: misplaced %s element\n", cur->name);
4753 }
4754 cur = cur->next;
4755 }
4756 }
4757 /*
4758 * Create a new frame using the params first
4759 */
4760 xsltApplyXSLTTemplate(ctxt, node, comp->templ->content, comp->templ,
4761 withParams);
4762 if (withParams != NULL)
4763 xsltFreeStackElemList(withParams);
4764
4765#ifdef WITH_XSLT_DEBUG_PROCESS
4766 if ((comp != NULL) && (comp->name != NULL))
4768 "call-template returned: name %s\n", comp->name));
4769#endif
4770}
xsltTemplatePtr xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI)
Definition: imports.c:357
char * name
Definition: compiler.c:66
xmlGenericErrorFunc xsltGenericError
Definition: xsltutils.c:502
void * xsltGenericErrorContext
Definition: xsltutils.c:503
@ XSLT_TRACE_CALL_TEMPLATE
Definition: xsltutils.h:109

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltChoose()

XSLTPUBFUN void XSLTCALL 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 5096 of file transform.c.

5098{
5100
5101 if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL))
5102 return;
5103
5104 /*
5105 * TODO: Content model checks should be done only at compilation
5106 * time.
5107 */
5108 cur = inst->children;
5109 if (cur == NULL) {
5110 xsltTransformError(ctxt, NULL, inst,
5111 "xsl:choose: The instruction has no content.\n");
5112 return;
5113 }
5114
5115#ifdef XSLT_REFACTORED
5116 /*
5117 * We don't check the content model during transformation.
5118 */
5119#else
5120 if ((! IS_XSLT_ELEM(cur)) || (! IS_XSLT_NAME(cur, "when"))) {
5121 xsltTransformError(ctxt, NULL, inst,
5122 "xsl:choose: xsl:when expected first\n");
5123 return;
5124 }
5125#endif
5126
5127 {
5128 int testRes = 0, res = 0;
5129
5130#ifdef XSLT_REFACTORED
5131 xsltStyleItemWhenPtr wcomp = NULL;
5132#else
5133 xsltStylePreCompPtr wcomp = NULL;
5134#endif
5135
5136 /*
5137 * Process xsl:when ---------------------------------------------------
5138 */
5139 while (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "when")) {
5140 wcomp = cur->psvi;
5141
5142 if ((wcomp == NULL) || (wcomp->test == NULL) ||
5143 (wcomp->comp == NULL))
5144 {
5146 "Internal error in xsltChoose(): "
5147 "The XSLT 'when' instruction was not compiled.\n");
5148 goto error;
5149 }
5150
5151
5152#ifdef WITH_DEBUGGER
5154 /*
5155 * TODO: Isn't comp->templ always NULL for xsl:choose?
5156 */
5157 xslHandleDebugger(cur, contextNode, NULL, ctxt);
5158 }
5159#endif
5160#ifdef WITH_XSLT_DEBUG_PROCESS
5162 "xsltChoose: test %s\n", wcomp->test));
5163#endif
5164
5165#ifdef XSLT_FAST_IF
5166 res = xsltPreCompEvalToBoolean(ctxt, contextNode, wcomp);
5167
5168 if (res == -1) {
5169 ctxt->state = XSLT_STATE_STOPPED;
5170 goto error;
5171 }
5172 testRes = (res == 1) ? 1 : 0;
5173
5174#else /* XSLT_FAST_IF */
5175
5176 res = xsltPreCompEval(ctxt, cotextNode, wcomp);
5177
5178 if (res != NULL) {
5179 if (res->type != XPATH_BOOLEAN)
5180 res = xmlXPathConvertBoolean(res);
5181 if (res->type == XPATH_BOOLEAN)
5182 testRes = res->boolval;
5183 else {
5184#ifdef WITH_XSLT_DEBUG_PROCESS
5186 "xsltChoose: test didn't evaluate to a boolean\n"));
5187#endif
5188 goto error;
5189 }
5190 xmlXPathFreeObject(res);
5191 res = NULL;
5192 } else {
5193 ctxt->state = XSLT_STATE_STOPPED;
5194 goto error;
5195 }
5196
5197#endif /* else of XSLT_FAST_IF */
5198
5199#ifdef WITH_XSLT_DEBUG_PROCESS
5201 "xsltChoose: test evaluate to %d\n", testRes));
5202#endif
5203 if (testRes)
5204 goto test_is_true;
5205
5206 cur = cur->next;
5207 }
5208
5209 /*
5210 * Process xsl:otherwise ----------------------------------------------
5211 */
5212 if (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "otherwise")) {
5213
5214#ifdef WITH_DEBUGGER
5216 xslHandleDebugger(cur, contextNode, NULL, ctxt);
5217#endif
5218
5219#ifdef WITH_XSLT_DEBUG_PROCESS
5221 "evaluating xsl:otherwise\n"));
5222#endif
5223 goto test_is_true;
5224 }
5225 goto exit;
5226
5227test_is_true:
5228
5229 goto process_sequence;
5230 }
5231
5232process_sequence:
5233
5234 /*
5235 * Instantiate the sequence constructor.
5236 */
5237 xsltApplySequenceConstructor(ctxt, ctxt->node, cur->children,
5238 NULL);
5239
5240exit:
5241error:
5242 return;
5243}
static int xsltPreCompEvalToBoolean(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltStylePreCompPtr comp)
Definition: transform.c:370
int xslDebugStatus
Definition: xsltutils.c:2366
@ XSLT_TRACE_CHOOSE
Definition: xsltutils.h:111

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltComment()

XSLTPUBFUN void XSLTCALL 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 4225 of file transform.c.

4226 {
4227 xmlChar *value = NULL;
4228 xmlNodePtr commentNode;
4229 int len;
4230
4231 value = xsltEvalTemplateString(ctxt, node, inst);
4232 /* TODO: use or generate the compiled form */
4233 len = xmlStrlen(value);
4234 if (len > 0) {
4235 if ((value[len-1] == '-') ||
4236 (xmlStrstr(value, BAD_CAST "--"))) {
4237 xsltTransformError(ctxt, NULL, inst,
4238 "xsl:comment : '--' or ending '-' not allowed in comment\n");
4239 /* fall through to try to catch further errors */
4240 }
4241 }
4242#ifdef WITH_XSLT_DEBUG_PROCESS
4243 if (value == NULL) {
4245 "xsltComment: empty\n"));
4246 } else {
4248 "xsltComment: content %s\n", value));
4249 }
4250#endif
4251
4252 commentNode = xmlNewComment(value);
4253 commentNode = xsltAddChild(ctxt->insert, commentNode);
4254
4255 if (value != NULL)
4256 xmlFree(value);
4257}
static xmlNodePtr xsltAddChild(xmlNodePtr parent, xmlNodePtr cur)
Definition: transform.c:751
GLenum GLsizei len
Definition: glext.h:6722
XMLPUBFUN xmlNodePtr XMLCALL xmlNewComment(const xmlChar *content)
XMLPUBFUN const xmlChar *XMLCALL xmlStrstr(const xmlChar *str, const xmlChar *val)
Definition: xmlstring.c:345
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426
@ XSLT_TRACE_COMMENT
Definition: xsltutils.h:105

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopy()

XSLTPUBFUN void XSLTCALL 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 3861 of file transform.c.

3863{
3864#ifdef XSLT_REFACTORED
3865 xsltStyleItemCopyPtr comp = (xsltStyleItemCopyPtr) castedComp;
3866#else
3867 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
3868#endif
3869 xmlNodePtr copy, oldInsert;
3870
3871 oldInsert = ctxt->insert;
3872 if (ctxt->insert != NULL) {
3873 switch (node->type) {
3874 case XML_TEXT_NODE:
3876 /*
3877 * This text comes from the stylesheet
3878 * For stylesheets, the set of whitespace-preserving
3879 * element names consists of just xsl:text.
3880 */
3881#ifdef WITH_XSLT_DEBUG_PROCESS
3882 if (node->type == XML_CDATA_SECTION_NODE) {
3884 "xsltCopy: CDATA text %s\n", node->content));
3885 } else {
3887 "xsltCopy: text %s\n", node->content));
3888 }
3889#endif
3890 xsltCopyText(ctxt, ctxt->insert, node, 0);
3891 break;
3892 case XML_DOCUMENT_NODE:
3894 break;
3895 case XML_ELEMENT_NODE:
3896 /*
3897 * REVISIT NOTE: The "fake" is a doc-node, not an element node.
3898 * REMOVED:
3899 * if (xmlStrEqual(node->name, BAD_CAST " fake node libxslt"))
3900 * return;
3901 */
3902
3903#ifdef WITH_XSLT_DEBUG_PROCESS
3905 "xsltCopy: node %s\n", node->name));
3906#endif
3907 copy = xsltShallowCopyElem(ctxt, node, ctxt->insert, 0);
3908 ctxt->insert = copy;
3909 if (comp->use != NULL) {
3910 xsltApplyAttributeSet(ctxt, node, inst, comp->use);
3911 }
3912 break;
3913 case XML_ATTRIBUTE_NODE: {
3914#ifdef WITH_XSLT_DEBUG_PROCESS
3916 "xsltCopy: attribute %s\n", node->name));
3917#endif
3918 /*
3919 * REVISIT: We could also raise an error if the parent is not
3920 * an element node.
3921 * OPTIMIZE TODO: Can we set the value/children of the
3922 * attribute without an intermediate copy of the string value?
3923 */
3924 xsltShallowCopyAttr(ctxt, inst, ctxt->insert, (xmlAttrPtr) node);
3925 break;
3926 }
3927 case XML_PI_NODE:
3928#ifdef WITH_XSLT_DEBUG_PROCESS
3930 "xsltCopy: PI %s\n", node->name));
3931#endif
3932 copy = xmlNewDocPI(ctxt->insert->doc, node->name,
3933 node->content);
3934 copy = xsltAddChild(ctxt->insert, copy);
3935 break;
3936 case XML_COMMENT_NODE:
3937#ifdef WITH_XSLT_DEBUG_PROCESS
3939 "xsltCopy: comment\n"));
3940#endif
3941 copy = xmlNewComment(node->content);
3942 copy = xsltAddChild(ctxt->insert, copy);
3943 break;
3944 case XML_NAMESPACE_DECL:
3945#ifdef WITH_XSLT_DEBUG_PROCESS
3947 "xsltCopy: namespace declaration\n"));
3948#endif
3949 xsltShallowCopyNsNode(ctxt, inst, ctxt->insert, (xmlNsPtr)node);
3950 break;
3951 default:
3952 break;
3953
3954 }
3955 }
3956
3957 switch (node->type) {
3958 case XML_DOCUMENT_NODE:
3960 case XML_ELEMENT_NODE:
3961 xsltApplySequenceConstructor(ctxt, ctxt->node, inst->children,
3962 NULL);
3963 break;
3964 default:
3965 break;
3966 }
3967 ctxt->insert = oldInsert;
3968}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
void xsltApplyAttributeSet(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, const xmlChar *attrSets)
Definition: attributes.c:1086
static xmlAttrPtr xsltShallowCopyAttr(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr target, xmlAttrPtr attr)
Definition: transform.c:1121
static xmlNsPtr xsltShallowCopyNsNode(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr insert, xmlNsPtr ns)
Definition: transform.c:1481
static xmlNodePtr xsltCopyText(xsltTransformContextPtr ctxt, xmlNodePtr target, xmlNodePtr cur, int interned)
Definition: transform.c:945
static xmlNodePtr xsltShallowCopyElem(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr insert, int isLRE)
Definition: transform.c:1296
@ XML_ATTRIBUTE_NODE
Definition: tree.h:161
@ XML_DOCUMENT_NODE
Definition: tree.h:168
@ XML_PI_NODE
Definition: tree.h:166
@ XML_COMMENT_NODE
Definition: tree.h:167
@ XML_HTML_DOCUMENT_NODE
Definition: tree.h:172
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content)
@ XSLT_TRACE_COPY
Definition: xsltutils.h:104

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopyOf()

XSLTPUBFUN void XSLTCALL 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 4335 of file transform.c.

4336 {
4337#ifdef XSLT_REFACTORED
4338 xsltStyleItemCopyOfPtr comp = (xsltStyleItemCopyOfPtr) castedComp;
4339#else
4340 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4341#endif
4342 xmlXPathObjectPtr res = NULL;
4343 xmlNodeSetPtr list = NULL;
4344 int i;
4345
4346 if ((ctxt == NULL) || (node == NULL) || (inst == NULL))
4347 return;
4348 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) {
4349 xsltTransformError(ctxt, NULL, inst,
4350 "xsl:copy-of : compilation failed\n");
4351 return;
4352 }
4353
4354 /*
4355 * SPEC XSLT 1.0:
4356 * "The xsl:copy-of element can be used to insert a result tree
4357 * fragment into the result tree, without first converting it to
4358 * a string as xsl:value-of does (see [7.6.1 Generating Text with
4359 * xsl:value-of]). The required select attribute contains an
4360 * expression. When the result of evaluating the expression is a
4361 * result tree fragment, the complete fragment is copied into the
4362 * result tree. When the result is a node-set, all the nodes in the
4363 * set are copied in document order into the result tree; copying
4364 * an element node copies the attribute nodes, namespace nodes and
4365 * children of the element node as well as the element node itself;
4366 * a root node is copied by copying its children. When the result
4367 * is neither a node-set nor a result tree fragment, the result is
4368 * converted to a string and then inserted into the result tree,
4369 * as with xsl:value-of.
4370 */
4371
4372#ifdef WITH_XSLT_DEBUG_PROCESS
4374 "xsltCopyOf: select %s\n", comp->select));
4375#endif
4376
4377 /*
4378 * Evaluate the "select" expression.
4379 */
4380 res = xsltPreCompEval(ctxt, node, comp);
4381
4382 if (res != NULL) {
4383 if (res->type == XPATH_NODESET) {
4384 /*
4385 * Node-set
4386 * --------
4387 */
4388#ifdef WITH_XSLT_DEBUG_PROCESS
4390 "xsltCopyOf: result is a node set\n"));
4391#endif
4392 list = res->nodesetval;
4393 if (list != NULL) {
4395 /*
4396 * The list is already sorted in document order by XPath.
4397 * Append everything in this order under ctxt->insert.
4398 */
4399 for (i = 0;i < list->nodeNr;i++) {
4400 cur = list->nodeTab[i];
4401 if (cur == NULL)
4402 continue;
4403 if ((cur->type == XML_DOCUMENT_NODE) ||
4404 (cur->type == XML_HTML_DOCUMENT_NODE))
4405 {
4406 xsltCopyTreeList(ctxt, inst,
4407 cur->children, ctxt->insert, 0, 0);
4408 } else if (cur->type == XML_ATTRIBUTE_NODE) {
4409 xsltShallowCopyAttr(ctxt, inst,
4410 ctxt->insert, (xmlAttrPtr) cur);
4411 } else {
4412 xsltCopyTree(ctxt, inst, cur, ctxt->insert, 0, 0);
4413 }
4414 }
4415 }
4416 } else if (res->type == XPATH_XSLT_TREE) {
4417 /*
4418 * Result tree fragment
4419 * --------------------
4420 * E.g. via <xsl:variable ...><foo/></xsl:variable>
4421 * Note that the root node of such trees is an xmlDocPtr in Libxslt.
4422 */
4423#ifdef WITH_XSLT_DEBUG_PROCESS
4425 "xsltCopyOf: result is a result tree fragment\n"));
4426#endif
4427 list = res->nodesetval;
4428 if ((list != NULL) && (list->nodeTab != NULL) &&
4429 (list->nodeTab[0] != NULL) &&
4430 (IS_XSLT_REAL_NODE(list->nodeTab[0])))
4431 {
4432 xsltCopyTreeList(ctxt, inst,
4433 list->nodeTab[0]->children, ctxt->insert, 0, 0);
4434 }
4435 } else {
4436 xmlChar *value = NULL;
4437 /*
4438 * Convert to a string.
4439 */
4440 value = xmlXPathCastToString(res);
4441 if (value == NULL) {
4442 xsltTransformError(ctxt, NULL, inst,
4443 "Internal error in xsltCopyOf(): "
4444 "failed to cast an XPath object to string.\n");
4445 ctxt->state = XSLT_STATE_STOPPED;
4446 } else {
4447 if (value[0] != 0) {
4448 /*
4449 * Append content as text node.
4450 */
4451 xsltCopyTextString(ctxt, ctxt->insert, value, 0);
4452 }
4453 xmlFree(value);
4454
4455#ifdef WITH_XSLT_DEBUG_PROCESS
4457 "xsltCopyOf: result %s\n", res->stringval));
4458#endif
4459 }
4460 }
4461 } else {
4462 ctxt->state = XSLT_STATE_STOPPED;
4463 }
4464
4465 if (res != NULL)
4466 xmlXPathFreeObject(res);
4467}
xmlNodePtr xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int noescape)
Definition: transform.c:849
static xmlNodePtr xsltCopyTreeList(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr list, xmlNodePtr insert, int isLRE, int topElemVisited)
Definition: transform.c:1388
static xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, xmlNodePtr node, xmlNodePtr insert, int isLRE, int topElemVisited)
Definition: transform.c:1592
@ XSLT_TRACE_COPY_OF
Definition: xsltutils.h:107

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltCopyTextString()

XSLTPUBFUN xmlNodePtr XSLTCALL 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 849 of file transform.c.

851{
853 int len;
854
855 if (string == NULL)
856 return(NULL);
857
858#ifdef WITH_XSLT_DEBUG_PROCESS
860 "xsltCopyTextString: copy text %s\n",
861 string));
862#endif
863
864 /*
865 * Play safe and reset the merging mechanism for every new
866 * target node.
867 */
868 if ((target == NULL) || (target->children == NULL)) {
869 ctxt->lasttext = NULL;
870 }
871
872 /* handle coalescing of text nodes here */
873 len = xmlStrlen(string);
874 if ((ctxt->type == XSLT_OUTPUT_XML) &&
875 (ctxt->style->cdataSection != NULL) &&
876 (target != NULL) &&
877 (target->type == XML_ELEMENT_NODE) &&
878 (((target->ns == NULL) &&
880 target->name, NULL) != NULL)) ||
881 ((target->ns != NULL) &&
883 target->name, target->ns->href) != NULL))))
884 {
885 /*
886 * Process "cdata-section-elements".
887 */
888 if ((target->last != NULL) &&
889 (target->last->type == XML_CDATA_SECTION_NODE))
890 {
891 return(xsltAddTextString(ctxt, target->last, string, len));
892 }
893 copy = xmlNewCDataBlock(ctxt->output, string, len);
894 } else if (noescape) {
895 /*
896 * Process "disable-output-escaping".
897 */
898 if ((target != NULL) && (target->last != NULL) &&
899 (target->last->type == XML_TEXT_NODE) &&
900 (target->last->name == xmlStringTextNoenc))
901 {
902 return(xsltAddTextString(ctxt, target->last, string, len));
903 }
904 copy = xmlNewTextLen(string, len);
905 if (copy != NULL)
906 copy->name = xmlStringTextNoenc;
907 } else {
908 /*
909 * Default processing.
910 */
911 if ((target != NULL) && (target->last != NULL) &&
912 (target->last->type == XML_TEXT_NODE) &&
913 (target->last->name == xmlStringText)) {
914 return(xsltAddTextString(ctxt, target->last, string, len));
915 }
916 copy = xmlNewTextLen(string, len);
917 }
918 if (copy != NULL && target != NULL)
920 if (copy != NULL) {
921 ctxt->lasttext = copy->content;
922 ctxt->lasttsize = len;
923 ctxt->lasttuse = len;
924 } else {
926 "xsltCopyTextString: text copy failed\n");
927 ctxt->lasttext = NULL;
928 }
929 return(copy);
930}
static xmlNodePtr xsltAddTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, const xmlChar *string, int len)
Definition: transform.c:777
GLenum target
Definition: glext.h:7315
XMLPUBVAR const xmlChar xmlStringText[]
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:476
XMLPUBFUN xmlNodePtr XMLCALL xmlNewTextLen(const xmlChar *content, int len)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len)
xmlHashTablePtr cdataSection
xsltStylesheetPtr style
const xmlChar * lasttext
@ XSLT_OUTPUT_XML
@ XSLT_TRACE_COPY_TEXT
Definition: xsltutils.h:101

Referenced by xsltCopyOf(), xsltCopyTree(), xsltNumberFormat(), and xsltValueOf().

◆ xsltDocumentElem()

XSLTPUBFUN void XSLTCALL xsltDocumentElem ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltDocumentElem: @ctxt: an XSLT processing context @node: The current node @inst: the instruction in the stylesheet @castedComp: precomputed information

Process an EXSLT/XSLT-1.1 document element

Definition at line 3323 of file transform.c.

3325{
3326#ifdef XSLT_REFACTORED
3327 xsltStyleItemDocumentPtr comp = (xsltStyleItemDocumentPtr) castedComp;
3328#else
3329 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
3330#endif
3332 int ret;
3333 xmlChar *filename = NULL, *prop, *elements;
3334 xmlChar *element, *end;
3335 xmlDocPtr res = NULL;
3336 xmlDocPtr oldOutput;
3337 xmlNodePtr oldInsert, root;
3338 const char *oldOutputFile;
3339 xsltOutputType oldType;
3340 xmlChar *URL = NULL;
3341 const xmlChar *method;
3342 const xmlChar *doctypePublic;
3343 const xmlChar *doctypeSystem;
3344 const xmlChar *version;
3345 const xmlChar *encoding;
3346 int redirect_write_append = 0;
3347
3348 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
3349 return;
3350
3351 if (comp->filename == NULL) {
3352
3353 if (xmlStrEqual(inst->name, (const xmlChar *) "output")) {
3354 /*
3355 * The element "output" is in the namespace XSLT_SAXON_NAMESPACE
3356 * (http://icl.com/saxon)
3357 * The @file is in no namespace.
3358 */
3359#ifdef WITH_XSLT_DEBUG_EXTRA
3361 "Found saxon:output extension\n");
3362#endif
3363 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3364 (const xmlChar *) "file",
3366
3367 if (URL == NULL)
3368 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3369 (const xmlChar *) "href",
3371 } else if (xmlStrEqual(inst->name, (const xmlChar *) "write")) {
3372#ifdef WITH_XSLT_DEBUG_EXTRA
3374 "Found xalan:write extension\n");
3375#endif
3376 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3377 (const xmlChar *)
3378 "select",
3380 if (URL != NULL) {
3381 xmlXPathCompExprPtr cmp;
3382 xmlChar *val;
3383
3384 /*
3385 * Trying to handle bug #59212
3386 * The value of the "select" attribute is an
3387 * XPath expression.
3388 * (see http://xml.apache.org/xalan-j/extensionslib.html#redirect)
3389 */
3390 cmp = xmlXPathCtxtCompile(ctxt->xpathCtxt, URL);
3391 val = xsltEvalXPathString(ctxt, cmp);
3392 xmlXPathFreeCompExpr(cmp);
3393 xmlFree(URL);
3394 URL = val;
3395 }
3396 if (URL == NULL)
3397 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3398 (const xmlChar *)
3399 "file",
3401 if (URL == NULL)
3402 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3403 (const xmlChar *)
3404 "href",
3406 } else if (xmlStrEqual(inst->name, (const xmlChar *) "document")) {
3407 URL = xsltEvalAttrValueTemplate(ctxt, inst,
3408 (const xmlChar *) "href",
3409 NULL);
3410 }
3411
3412 } else {
3413 URL = xmlStrdup(comp->filename);
3414 }
3415
3416 if (URL == NULL) {
3417 xsltTransformError(ctxt, NULL, inst,
3418 "xsltDocumentElem: href/URI-Reference not found\n");
3419 return;
3420 }
3421
3422 /*
3423 * If the computation failed, it's likely that the URL wasn't escaped
3424 */
3425 filename = xmlBuildURI(URL, (const xmlChar *) ctxt->outputFile);
3426 if (filename == NULL) {
3427 xmlChar *escURL;
3428
3429 escURL=xmlURIEscapeStr(URL, BAD_CAST ":/.?,");
3430 if (escURL != NULL) {
3431 filename = xmlBuildURI(escURL, (const xmlChar *) ctxt->outputFile);
3432 xmlFree(escURL);
3433 }
3434 }
3435
3436 if (filename == NULL) {
3437 xsltTransformError(ctxt, NULL, inst,
3438 "xsltDocumentElem: URL computation failed for %s\n",
3439 URL);
3440 xmlFree(URL);
3441 return;
3442 }
3443
3444 /*
3445 * Security checking: can we write to this resource
3446 */
3447 if (ctxt->sec != NULL) {
3448 ret = xsltCheckWrite(ctxt->sec, ctxt, filename);
3449 if (ret <= 0) {
3450 if (ret == 0)
3451 xsltTransformError(ctxt, NULL, inst,
3452 "xsltDocumentElem: write rights for %s denied\n",
3453 filename);
3454 xmlFree(URL);
3456 return;
3457 }
3458 }
3459
3460 oldOutputFile = ctxt->outputFile;
3461 oldOutput = ctxt->output;
3462 oldInsert = ctxt->insert;
3463 oldType = ctxt->type;
3464 ctxt->outputFile = (const char *) filename;
3465
3467 if (style == NULL) {
3468 xsltTransformError(ctxt, NULL, inst,
3469 "xsltDocumentElem: out of memory\n");
3470 goto error;
3471 }
3472
3473 /*
3474 * Version described in 1.1 draft allows full parameterization
3475 * of the output.
3476 */
3477 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3478 (const xmlChar *) "version",
3479 NULL);
3480 if (prop != NULL) {
3481 if (style->version != NULL)
3482 xmlFree(style->version);
3483 style->version = prop;
3484 }
3485 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3486 (const xmlChar *) "encoding",
3487 NULL);
3488 if (prop != NULL) {
3489 if (style->encoding != NULL)
3490 xmlFree(style->encoding);
3491 style->encoding = prop;
3492 }
3493 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3494 (const xmlChar *) "method",
3495 NULL);
3496 if (prop != NULL) {
3497 const xmlChar *URI;
3498
3499 if (style->method != NULL)
3500 xmlFree(style->method);
3501 style->method = NULL;
3502 if (style->methodURI != NULL)
3503 xmlFree(style->methodURI);
3504 style->methodURI = NULL;
3505
3506 URI = xsltGetQNameURI(inst, &prop);
3507 if (prop == NULL) {
3508 if (style != NULL) style->errors++;
3509 } else if (URI == NULL) {
3510 if ((xmlStrEqual(prop, (const xmlChar *) "xml")) ||
3511 (xmlStrEqual(prop, (const xmlChar *) "html")) ||
3512 (xmlStrEqual(prop, (const xmlChar *) "text"))) {
3513 style->method = prop;
3514 } else {
3515 xsltTransformError(ctxt, NULL, inst,
3516 "invalid value for method: %s\n", prop);
3517 if (style != NULL) style->warnings++;
3518 }
3519 } else {
3520 style->method = prop;
3521 style->methodURI = xmlStrdup(URI);
3522 }
3523 }
3524 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3525 (const xmlChar *)
3526 "doctype-system", NULL);
3527 if (prop != NULL) {
3528 if (style->doctypeSystem != NULL)
3529 xmlFree(style->doctypeSystem);
3530 style->doctypeSystem = prop;
3531 }
3532 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3533 (const xmlChar *)
3534 "doctype-public", NULL);
3535 if (prop != NULL) {
3536 if (style->doctypePublic != NULL)
3537 xmlFree(style->doctypePublic);
3538 style->doctypePublic = prop;
3539 }
3540 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3541 (const xmlChar *) "standalone",
3542 NULL);
3543 if (prop != NULL) {
3544 if (xmlStrEqual(prop, (const xmlChar *) "yes")) {
3545 style->standalone = 1;
3546 } else if (xmlStrEqual(prop, (const xmlChar *) "no")) {
3547 style->standalone = 0;
3548 } else {
3549 xsltTransformError(ctxt, NULL, inst,
3550 "invalid value for standalone: %s\n",
3551 prop);
3552 if (style != NULL) style->warnings++;
3553 }
3554 xmlFree(prop);
3555 }
3556
3557 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3558 (const xmlChar *) "indent",
3559 NULL);
3560 if (prop != NULL) {
3561 if (xmlStrEqual(prop, (const xmlChar *) "yes")) {
3562 style->indent = 1;
3563 } else if (xmlStrEqual(prop, (const xmlChar *) "no")) {
3564 style->indent = 0;
3565 } else {
3566 xsltTransformError(ctxt, NULL, inst,
3567 "invalid value for indent: %s\n", prop);
3568 if (style != NULL) style->warnings++;
3569 }
3570 xmlFree(prop);
3571 }
3572
3573 prop = xsltEvalAttrValueTemplate(ctxt, inst,
3574 (const xmlChar *)
3575 "omit-xml-declaration",
3576 NULL);
3577 if (prop != NULL) {
3578 if (xmlStrEqual(prop, (const xmlChar *) "yes")) {
3579 style->omitXmlDeclaration = 1;
3580 } else if (xmlStrEqual(prop, (const xmlChar *) "no")) {
3581 style->omitXmlDeclaration = 0;
3582 } else {
3583 xsltTransformError(ctxt, NULL, inst,
3584 "invalid value for omit-xml-declaration: %s\n",
3585 prop);
3586 if (style != NULL) style->warnings++;
3587 }
3588 xmlFree(prop);
3589 }
3590
3591 elements = xsltEvalAttrValueTemplate(ctxt, inst,
3592 (const xmlChar *)
3593 "cdata-section-elements",
3594 NULL);
3595 if (elements != NULL) {
3596 if (style->stripSpaces == NULL)
3597 style->stripSpaces = xmlHashCreate(10);
3598 if (style->stripSpaces == NULL) {
3599 xmlFree(elements);
3600 return;
3601 }
3602
3603 element = elements;
3604 while (*element != 0) {
3605 while (xmlIsBlank_ch(*element))
3606 element++;
3607 if (*element == 0)
3608 break;
3609 end = element;
3610 while ((*end != 0) && (!xmlIsBlank_ch(*end)))
3611 end++;
3613 if (element) {
3614 const xmlChar *URI;
3615
3616#ifdef WITH_XSLT_DEBUG_PARSING
3618 "add cdata section output element %s\n",
3619 element);
3620#endif
3621 URI = xsltGetQNameURI(inst, &element);
3622
3623 xmlHashAddEntry2(style->stripSpaces, element, URI,
3624 (xmlChar *) "cdata");
3626 }
3627 element = end;
3628 }
3629 xmlFree(elements);
3630 }
3631
3632 /*
3633 * Create a new document tree and process the element template
3634 */
3636 XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
3637 XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
3640
3641 if ((method != NULL) &&
3642 (!xmlStrEqual(method, (const xmlChar *) "xml"))) {
3643 if (xmlStrEqual(method, (const xmlChar *) "html")) {
3644 ctxt->type = XSLT_OUTPUT_HTML;
3645 if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
3646 res = htmlNewDoc(doctypeSystem, doctypePublic);
3647 else {
3648 if (version != NULL) {
3649#ifdef XSLT_GENERATE_HTML_DOCTYPE
3650 xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem);
3651#endif
3652 }
3653 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic);
3654 }
3655 if (res == NULL)
3656 goto error;
3657 res->dict = ctxt->dict;
3658 xmlDictReference(res->dict);
3659 } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) {
3660 xsltTransformError(ctxt, NULL, inst,
3661 "xsltDocumentElem: unsupported method xhtml\n");
3662 ctxt->type = XSLT_OUTPUT_HTML;
3663 res = htmlNewDocNoDtD(doctypeSystem, doctypePublic);
3664 if (res == NULL)
3665 goto error;
3666 res->dict = ctxt->dict;
3667 xmlDictReference(res->dict);
3668 } else if (xmlStrEqual(method, (const xmlChar *) "text")) {
3669 ctxt->type = XSLT_OUTPUT_TEXT;
3670 res = xmlNewDoc(style->version);
3671 if (res == NULL)
3672 goto error;
3673 res->dict = ctxt->dict;
3674 xmlDictReference(res->dict);
3675#ifdef WITH_XSLT_DEBUG
3677 "reusing transformation dict for output\n");
3678#endif
3679 } else {
3680 xsltTransformError(ctxt, NULL, inst,
3681 "xsltDocumentElem: unsupported method (%s)\n",
3682 method);
3683 goto error;
3684 }
3685 } else {
3686 ctxt->type = XSLT_OUTPUT_XML;
3687 res = xmlNewDoc(style->version);
3688 if (res == NULL)
3689 goto error;
3690 res->dict = ctxt->dict;
3691 xmlDictReference(res->dict);
3692#ifdef WITH_XSLT_DEBUG
3694 "reusing transformation dict for output\n");
3695#endif
3696 }
3697 res->charset = XML_CHAR_ENCODING_UTF8;
3698 if (encoding != NULL)
3699 res->encoding = xmlStrdup(encoding);
3700 ctxt->output = res;
3701 ctxt->insert = (xmlNodePtr) res;
3703
3704 /*
3705 * Do some post processing work depending on the generated output
3706 */
3708 if (root != NULL) {
3709 const xmlChar *doctype = NULL;
3710
3711 if ((root->ns != NULL) && (root->ns->prefix != NULL))
3712 doctype = xmlDictQLookup(ctxt->dict, root->ns->prefix, root->name);
3713 if (doctype == NULL)
3714 doctype = root->name;
3715
3716 /*
3717 * Apply the default selection of the method
3718 */
3719 if ((method == NULL) &&
3720 (root->ns == NULL) &&
3721 (!xmlStrcasecmp(root->name, (const xmlChar *) "html"))) {
3722 xmlNodePtr tmp;
3723
3724 tmp = res->children;
3725 while ((tmp != NULL) && (tmp != root)) {
3726 if (tmp->type == XML_ELEMENT_NODE)
3727 break;
3728 if ((tmp->type == XML_TEXT_NODE) && (!xmlIsBlankNode(tmp)))
3729 break;
3730 tmp = tmp->next;
3731 }
3732 if (tmp == root) {
3733 ctxt->type = XSLT_OUTPUT_HTML;
3735 if (((doctypePublic != NULL) || (doctypeSystem != NULL))) {
3736 res->intSubset = xmlCreateIntSubset(res, doctype,
3737 doctypePublic,
3738 doctypeSystem);
3739#ifdef XSLT_GENERATE_HTML_DOCTYPE
3740 } else if (version != NULL) {
3741 xsltGetHTMLIDs(version, &doctypePublic,
3742 &doctypeSystem);
3743 if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
3744 res->intSubset =
3745 xmlCreateIntSubset(res, doctype,
3746 doctypePublic,
3747 doctypeSystem);
3748#endif
3749 }
3750 }
3751
3752 }
3753 if (ctxt->type == XSLT_OUTPUT_XML) {
3754 XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
3755 XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
3756 if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
3757 res->intSubset = xmlCreateIntSubset(res, doctype,
3758 doctypePublic,
3759 doctypeSystem);
3760 }
3761 }
3762
3763 /*
3764 * Calls to redirect:write also take an optional attribute append.
3765 * Attribute append="true|yes" which will attempt to simply append
3766 * to an existing file instead of always opening a new file. The
3767 * default behavior of always overwriting the file still happens
3768 * if we do not specify append.
3769 * Note that append use will forbid use of remote URI target.
3770 */
3771 prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"append",
3772 NULL);
3773 if (prop != NULL) {
3774 if (xmlStrEqual(prop, (const xmlChar *) "true") ||
3775 xmlStrEqual(prop, (const xmlChar *) "yes")) {
3776 style->omitXmlDeclaration = 1;
3777 redirect_write_append = 1;
3778 } else
3779 style->omitXmlDeclaration = 0;
3780 xmlFree(prop);
3781 }
3782
3783 if (redirect_write_append) {
3784 FILE *f;
3785
3786 f = fopen((const char *) filename, "ab");
3787 if (f == NULL) {
3788 ret = -1;
3789 } else {
3791 fclose(f);
3792 }
3793 } else {
3794 ret = xsltSaveResultToFilename((const char *) filename, res, style, 0);
3795 }
3796 if (ret < 0) {
3797 xsltTransformError(ctxt, NULL, inst,
3798 "xsltDocumentElem: unable to save to %s\n",
3799 filename);
3800#ifdef WITH_XSLT_DEBUG_EXTRA
3801 } else {
3803 "Wrote %d bytes to %s\n", ret, filename);
3804#endif
3805 }
3806
3807 error:
3808 ctxt->output = oldOutput;
3809 ctxt->insert = oldInsert;
3810 ctxt->type = oldType;
3811 ctxt->outputFile = oldOutputFile;
3812 if (URL != NULL)
3813 xmlFree(URL);
3814 if (filename != NULL)
3816 if (style != NULL)
3818 if (res != NULL)
3819 xmlFreeDoc(res);
3820}
struct _root root
#define xmlIsBlank_ch(c)
Definition: chvalid.h:88
int xsltCheckWrite(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:335
static int xsltGetHTMLIDs(const xmlChar *version, const xmlChar **publicID, const xmlChar **systemID)
Definition: transform.c:5581
static const WCHAR version[]
Definition: asmname.c:66
method
Definition: dragdrop.c:54
@ XML_CHAR_ENCODING_UTF8
Definition: encoding.h:59
#define XSLT_XALAN_NAMESPACE
Definition: extra.h:48
#define XSLT_SAXON_NAMESPACE
Definition: extra.h:34
GLuint GLuint end
Definition: gl.h:1545
GLfloat f
Definition: glext.h:7540
GLuint GLfloat * val
Definition: glext.h:7180
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
#define f
Definition: ke_i.h:83
#define cmp(status, error)
Definition: error.c:114
XMLPUBFUN const xmlChar *XMLCALL xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name)
Definition: dict.c:1115
XMLPUBFUN int XMLCALL xmlDictReference(xmlDictPtr dict)
Definition: dict.c:647
XMLPUBFUN int XMLCALL xmlHashAddEntry2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, void *userdata)
Definition: hash.c:406
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreate(int size)
Definition: hash.c:176
XMLPUBFUN xmlNodePtr XMLCALL xmlDocGetRootElement(const xmlDoc *doc)
XMLPUBFUN xmlDtdPtr XMLCALL xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBFUN xmlDocPtr XMLCALL xmlNewDoc(const xmlChar *version)
XMLPUBFUN int XMLCALL xmlIsBlankNode(const xmlNode *node)
#define XSLT_GET_IMPORT_PTR(res, style, name)
Definition: imports.h:27
struct _xmlNode * next
Definition: tree.h:496
xmlChar * xsltEvalXPathString(xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp)
Definition: templates.c:171
XMLPUBFUN xmlChar *XMLCALL xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
Definition: uri.c:1679
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1892
int ret
static char * encoding
Definition: xmllint.c:155
XMLPUBFUN xmlChar *XMLCALL xmlStrndup(const xmlChar *cur, int len)
Definition: xmlstring.c:42
XMLPUBFUN int XMLCALL xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:275
xsltOutputType
@ XSLT_OUTPUT_HTML
@ XSLT_OUTPUT_TEXT
xsltStylesheetPtr xsltNewStylesheet(void)
Definition: xslt.c:795
void xsltFreeStylesheet(xsltStylesheetPtr style)
Definition: xslt.c:950
const xmlChar * xsltGetQNameURI(xmlNodePtr node, xmlChar **name)
Definition: xsltutils.c:753
int xsltSaveResultToFilename(const char *URL, xmlDocPtr result, xsltStylesheetPtr style, int compression)
Definition: xsltutils.c:1636
int xsltSaveResultToFile(FILE *file, xmlDocPtr result, xsltStylesheetPtr style)
Definition: xsltutils.c:1680

Referenced by xsltNewStylePreComp(), xsltRegisterAllExtras(), and xsltStylePreCompute().

◆ xsltElement()

XSLTPUBFUN void XSLTCALL xsltElement ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltElement: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the xslt element node @castedComp: precomputed information

Process the xslt element node on the source node

Definition at line 4017 of file transform.c.

4018 {
4019#ifdef XSLT_REFACTORED
4020 xsltStyleItemElementPtr comp = (xsltStyleItemElementPtr) castedComp;
4021#else
4022 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4023#endif
4024 xmlChar *prop = NULL;
4025 const xmlChar *name, *prefix = NULL, *nsName = NULL;
4027 xmlNodePtr oldInsert;
4028
4029 if (ctxt->insert == NULL)
4030 return;
4031
4032 /*
4033 * A comp->has_name == 0 indicates that we need to skip this instruction,
4034 * since it was evaluated to be invalid already during compilation.
4035 */
4036 if (!comp->has_name)
4037 return;
4038
4039 /*
4040 * stack and saves
4041 */
4042 oldInsert = ctxt->insert;
4043
4044 if (comp->name == NULL) {
4045 /* TODO: fix attr acquisition wrt to the XSLT namespace */
4046 prop = xsltEvalAttrValueTemplate(ctxt, inst,
4047 (const xmlChar *) "name", XSLT_NAMESPACE);
4048 if (prop == NULL) {
4049 xsltTransformError(ctxt, NULL, inst,
4050 "xsl:element: The attribute 'name' is missing.\n");
4051 goto error;
4052 }
4053 if (xmlValidateQName(prop, 0)) {
4054 xsltTransformError(ctxt, NULL, inst,
4055 "xsl:element: The effective name '%s' is not a "
4056 "valid QName.\n", prop);
4057 /* we fall through to catch any further errors, if possible */
4058 }
4059 name = xsltSplitQName(ctxt->dict, prop, &prefix);
4060 xmlFree(prop);
4061 } else {
4062 /*
4063 * The "name" value was static.
4064 */
4065#ifdef XSLT_REFACTORED
4066 prefix = comp->nsPrefix;
4067 name = comp->name;
4068#else
4069 name = xsltSplitQName(ctxt->dict, comp->name, &prefix);
4070#endif
4071 }
4072
4073 /*
4074 * Create the new element
4075 */
4076 if (ctxt->output->dict == ctxt->dict) {
4078 } else {
4079 copy = xmlNewDocNode(ctxt->output, NULL, (xmlChar *)name, NULL);
4080 }
4081 if (copy == NULL) {
4082 xsltTransformError(ctxt, NULL, inst,
4083 "xsl:element : creation of %s failed\n", name);
4084 return;
4085 }
4086 copy = xsltAddChild(ctxt->insert, copy);
4087 if (copy == NULL) {
4088 xsltTransformError(ctxt, NULL, inst,
4089 "xsl:element : xsltAddChild failed\n");
4090 return;
4091 }
4092
4093 /*
4094 * Namespace
4095 * ---------
4096 */
4097 if (comp->has_ns) {
4098 if (comp->ns != NULL) {
4099 /*
4100 * No AVT; just plain text for the namespace name.
4101 */
4102 if (comp->ns[0] != 0)
4103 nsName = comp->ns;
4104 } else {
4105 xmlChar *tmpNsName;
4106 /*
4107 * Eval the AVT.
4108 */
4109 /* TODO: check attr acquisition wrt to the XSLT namespace */
4110 tmpNsName = xsltEvalAttrValueTemplate(ctxt, inst,
4111 (const xmlChar *) "namespace", XSLT_NAMESPACE);
4112 /*
4113 * SPEC XSLT 1.0:
4114 * "If the string is empty, then the expanded-name of the
4115 * attribute has a null namespace URI."
4116 */
4117 if ((tmpNsName != NULL) && (tmpNsName[0] != 0))
4118 nsName = xmlDictLookup(ctxt->dict, BAD_CAST tmpNsName, -1);
4119 xmlFree(tmpNsName);
4120 }
4121
4122 if (xmlStrEqual(nsName, BAD_CAST "http://www.w3.org/2000/xmlns/")) {
4123 xsltTransformError(ctxt, NULL, inst,
4124 "xsl:attribute: Namespace http://www.w3.org/2000/xmlns/ "
4125 "forbidden.\n");
4126 goto error;
4127 }
4128 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
4129 prefix = BAD_CAST "xml";
4130 } else if (xmlStrEqual(prefix, BAD_CAST "xml")) {
4131 prefix = NULL;
4132 }
4133 } else {
4134 xmlNsPtr ns;
4135 /*
4136 * SPEC XSLT 1.0:
4137 * "If the namespace attribute is not present, then the QName is
4138 * expanded into an expanded-name using the namespace declarations
4139 * in effect for the xsl:element element, including any default
4140 * namespace declaration.
4141 */
4142 ns = xmlSearchNs(inst->doc, inst, prefix);
4143 if (ns == NULL) {
4144 /*
4145 * TODO: Check this in the compilation layer in case it's a
4146 * static value.
4147 */
4148 if (prefix != NULL) {
4149 xsltTransformError(ctxt, NULL, inst,
4150 "xsl:element: The QName '%s:%s' has no "
4151 "namespace binding in scope in the stylesheet; "
4152 "this is an error, since the namespace was not "
4153 "specified by the instruction itself.\n", prefix, name);
4154 }
4155 } else
4156 nsName = ns->href;
4157 }
4158 /*
4159 * Find/create a matching ns-decl in the result tree.
4160 */
4161 if (nsName != NULL) {
4162 if (xmlStrEqual(prefix, BAD_CAST "xmlns")) {
4163 /* Don't use a prefix of "xmlns" */
4164 xmlChar *pref = xmlStrdup(BAD_CAST "ns_1");
4165
4166 copy->ns = xsltGetSpecialNamespace(ctxt, inst, nsName, pref, copy);
4167
4168 xmlFree(pref);
4169 } else {
4170 copy->ns = xsltGetSpecialNamespace(ctxt, inst, nsName, prefix,
4171 copy);
4172 }
4173 } else if ((copy->parent != NULL) &&
4174 (copy->parent->type == XML_ELEMENT_NODE) &&
4175 (copy->parent->ns != NULL))
4176 {
4177 /*
4178 * "Undeclare" the default namespace.
4179 */
4180 xsltGetSpecialNamespace(ctxt, inst, NULL, NULL, copy);
4181 }
4182
4183 ctxt->insert = copy;
4184
4185 if (comp->has_use) {
4186 if (comp->use != NULL) {
4187 xsltApplyAttributeSet(ctxt, node, inst, comp->use);
4188 } else {
4189 xmlChar *attrSets = NULL;
4190 /*
4191 * BUG TODO: use-attribute-sets is not a value template.
4192 * use-attribute-sets = qnames
4193 */
4194 attrSets = xsltEvalAttrValueTemplate(ctxt, inst,
4195 (const xmlChar *)"use-attribute-sets", NULL);
4196 if (attrSets != NULL) {
4197 xsltApplyAttributeSet(ctxt, node, inst, attrSets);
4198 xmlFree(attrSets);
4199 }
4200 }
4201 }
4202 /*
4203 * Instantiate the sequence constructor.
4204 */
4205 if (inst->children != NULL)
4206 xsltApplySequenceConstructor(ctxt, ctxt->node, inst->children,
4207 NULL);
4208
4209error:
4210 ctxt->insert = oldInsert;
4211 return;
4212}
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocNodeEatName(xmlDocPtr doc, xmlNsPtr ns, xmlChar *name, const xmlChar *content)
struct _xmlDict * dict
Definition: tree.h:580

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltForEach()

XSLTPUBFUN void XSLTCALL xsltForEach ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltForEach: @ctxt: an XSLT transformation context @contextNode: the "current node" in the source tree @inst: the element node of the xsl:for-each instruction @castedComp: the compiled information of the instruction

Process the xslt for-each node on the source node

Definition at line 5361 of file transform.c.

5363{
5364#ifdef XSLT_REFACTORED
5365 xsltStyleItemForEachPtr comp = (xsltStyleItemForEachPtr) castedComp;
5366#else
5367 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
5368#endif
5369 int i;
5370 xmlXPathObjectPtr res = NULL;
5371 xmlNodePtr cur, curInst;
5372 xmlNodeSetPtr list = NULL;
5373 xmlNodeSetPtr oldList;
5374 int oldXPProximityPosition, oldXPContextSize;
5375 xmlNodePtr oldContextNode;
5376 xsltTemplatePtr oldCurTemplRule;
5377 xmlDocPtr oldXPDoc;
5378 xsltDocumentPtr oldDocInfo;
5379 xmlXPathContextPtr xpctxt;
5380
5381 if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL)) {
5383 "xsltForEach(): Bad arguments.\n");
5384 return;
5385 }
5386
5387 if (comp == NULL) {
5388 xsltTransformError(ctxt, NULL, inst,
5389 "Internal error in xsltForEach(): "
5390 "The XSLT 'for-each' instruction was not compiled.\n");
5391 return;
5392 }
5393 if ((comp->select == NULL) || (comp->comp == NULL)) {
5394 xsltTransformError(ctxt, NULL, inst,
5395 "Internal error in xsltForEach(): "
5396 "The selecting expression of the XSLT 'for-each' "
5397 "instruction was not compiled correctly.\n");
5398 return;
5399 }
5400 xpctxt = ctxt->xpathCtxt;
5401
5402#ifdef WITH_XSLT_DEBUG_PROCESS
5404 "xsltForEach: select %s\n", comp->select));
5405#endif
5406
5407 /*
5408 * Save context states.
5409 */
5410 oldDocInfo = ctxt->document;
5411 oldList = ctxt->nodeList;
5412 oldContextNode = ctxt->node;
5413 /*
5414 * The "current template rule" is cleared for the instantiation of
5415 * xsl:for-each.
5416 */
5417 oldCurTemplRule = ctxt->currentTemplateRule;
5418 ctxt->currentTemplateRule = NULL;
5419
5420 oldXPDoc = xpctxt->doc;
5421 oldXPProximityPosition = xpctxt->proximityPosition;
5422 oldXPContextSize = xpctxt->contextSize;
5423
5424 /*
5425 * Evaluate the 'select' expression.
5426 */
5427 res = xsltPreCompEval(ctxt, contextNode, comp);
5428
5429 if (res != NULL) {
5430 if (res->type == XPATH_NODESET)
5431 list = res->nodesetval;
5432 else {
5433 xsltTransformError(ctxt, NULL, inst,
5434 "The 'select' expression does not evaluate to a node set.\n");
5435
5436#ifdef WITH_XSLT_DEBUG_PROCESS
5438 "xsltForEach: select didn't evaluate to a node list\n"));
5439#endif
5440 goto error;
5441 }
5442 } else {
5443 xsltTransformError(ctxt, NULL, inst,
5444 "Failed to evaluate the 'select' expression.\n");
5445 ctxt->state = XSLT_STATE_STOPPED;
5446 goto error;
5447 }
5448
5449 if ((list == NULL) || (list->nodeNr <= 0))
5450 goto exit;
5451
5452#ifdef WITH_XSLT_DEBUG_PROCESS
5454 "xsltForEach: select evaluates to %d nodes\n", list->nodeNr));
5455#endif
5456
5457 /*
5458 * Set the list; this has to be done already here for xsltDoSortFunction().
5459 */
5460 ctxt->nodeList = list;
5461 /*
5462 * Handle xsl:sort instructions and skip them for further processing.
5463 * BUG TODO: We are not using namespaced potentially defined on the
5464 * xsl:sort element; XPath expression might fail.
5465 */
5466 curInst = inst->children;
5467 if (IS_XSLT_ELEM(curInst) && IS_XSLT_NAME(curInst, "sort")) {
5468 int nbsorts = 0;
5470
5471 sorts[nbsorts++] = curInst;
5472
5473#ifdef WITH_DEBUGGER
5475 xslHandleDebugger(curInst, contextNode, NULL, ctxt);
5476#endif
5477
5478 curInst = curInst->next;
5479 while (IS_XSLT_ELEM(curInst) && IS_XSLT_NAME(curInst, "sort")) {
5480 if (nbsorts >= XSLT_MAX_SORT) {
5481 xsltTransformError(ctxt, NULL, curInst,
5482 "The number of xsl:sort instructions exceeds the "
5483 "maximum (%d) allowed by this processor.\n",
5485 goto error;
5486 } else {
5487 sorts[nbsorts++] = curInst;
5488 }
5489
5490#ifdef WITH_DEBUGGER
5492 xslHandleDebugger(curInst, contextNode, NULL, ctxt);
5493#endif
5494 curInst = curInst->next;
5495 }
5496 xsltDoSortFunction(ctxt, sorts, nbsorts);
5497 }
5498 xpctxt->contextSize = list->nodeNr;
5499 /*
5500 * Instantiate the sequence constructor for each selected node.
5501 */
5502 for (i = 0; i < list->nodeNr; i++) {
5503 cur = list->nodeTab[i];
5504 /*
5505 * The selected node becomes the "current node".
5506 */
5507 ctxt->node = cur;
5508 /*
5509 * An xsl:for-each can change the current context doc.
5510 * OPTIMIZE TODO: Get rid of the need to set the context doc.
5511 */
5512 if ((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL))
5513 xpctxt->doc = cur->doc;
5514
5515 xpctxt->proximityPosition = i + 1;
5516
5517 xsltApplySequenceConstructor(ctxt, cur, curInst, NULL);
5518 }
5519
5520exit:
5521error:
5522 if (res != NULL)
5523 xmlXPathFreeObject(res);
5524 /*
5525 * Restore old states.
5526 */
5527 ctxt->document = oldDocInfo;
5528 ctxt->nodeList = oldList;
5529 ctxt->node = oldContextNode;
5530 ctxt->currentTemplateRule = oldCurTemplRule;
5531
5532 xpctxt->doc = oldXPDoc;
5533 xpctxt->contextSize = oldXPContextSize;
5534 xpctxt->proximityPosition = oldXPProximityPosition;
5535}
@ XSLT_TRACE_FOR_EACH
Definition: xsltutils.h:113

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltFreeTransformContext()

XSLTPUBFUN void XSLTCALL xsltFreeTransformContext ( xsltTransformContextPtr  ctxt)

xsltFreeTransformContext: @ctxt: an XSLT parser context

Free up the memory allocated by @ctxt

Definition at line 689 of file transform.c.

689 {
690 if (ctxt == NULL)
691 return;
692
693 /*
694 * Shutdown the extension modules associated to the stylesheet
695 * used if needed.
696 */
698
699 if (ctxt->xpathCtxt != NULL) {
700 ctxt->xpathCtxt->nsHash = NULL;
701 xmlXPathFreeContext(ctxt->xpathCtxt);
702 }
703 if (ctxt->templTab != NULL)
704 xmlFree(ctxt->templTab);
705 if (ctxt->varsTab != NULL)
706 xmlFree(ctxt->varsTab);
707 if (ctxt->profTab != NULL)
708 xmlFree(ctxt->profTab);
709 if ((ctxt->extrasNr > 0) && (ctxt->extras != NULL)) {
710 int i;
711
712 for (i = 0;i < ctxt->extrasNr;i++) {
713 if ((ctxt->extras[i].deallocate != NULL) &&
714 (ctxt->extras[i].info != NULL))
715 ctxt->extras[i].deallocate(ctxt->extras[i].info);
716 }
717 xmlFree(ctxt->extras);
718 }
720 xsltFreeDocuments(ctxt);
721 xsltFreeCtxtExts(ctxt);
722 xsltFreeRVTs(ctxt);
724 xmlDictFree(ctxt->dict);
725#ifdef WITH_XSLT_DEBUG
727 "freeing transformation dictionary\n");
728#endif
729 memset(ctxt, -1, sizeof(xsltTransformContext));
730 xmlFree(ctxt);
731}
void xsltFreeCtxtExts(xsltTransformContextPtr ctxt)
Definition: extensions.c:642
void xsltShutdownCtxtExts(xsltTransformContextPtr ctxt)
Definition: extensions.c:1081
static void xsltTransformCacheFree(xsltTransformCachePtr cache)
Definition: transform.c:486
void xsltFreeDocuments(xsltTransformContextPtr ctxt)
Definition: documents.c:234
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:802
#define memset(x, y, z)
Definition: compat.h:39
xmlFreeFunc deallocate
xsltTemplatePtr * templTab
xsltTransformCachePtr cache
xsltRuntimeExtraPtr extras
xsltStackElemPtr * varsTab
void xsltFreeRVTs(xsltTransformContextPtr ctxt)
Definition: variables.c:416
void xsltFreeGlobalVariables(xsltTransformContextPtr ctxt)
Definition: variables.c:2227

Referenced by xsltApplyStylesheetInternal(), and xsltNewTransformContext().

◆ xsltGetXIncludeDefault()

XSLTPUBFUN int XSLTCALL xsltGetXIncludeDefault ( void  )

xsltGetXIncludeDefault:

Provides the default state for XInclude processing

Returns 0 if there is no processing 1 otherwise

Definition at line 437 of file transform.c.

437 {
438 return(xsltDoXIncludeDefault);
439}
static int xsltDoXIncludeDefault
Definition: transform.c:416

Referenced by xsltNewTransformContext().

◆ xsltIf()

XSLTPUBFUN void XSLTCALL xsltIf ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltIf: @ctxt: a XSLT process context @contextNode: the current node in the source tree @inst: the xsl:if instruction @castedComp: compiled information of the instruction

Processes the xsl:if instruction on the source node.

Definition at line 5255 of file transform.c.

5257{
5258 int res = 0;
5259
5260#ifdef XSLT_REFACTORED
5261 xsltStyleItemIfPtr comp = (xsltStyleItemIfPtr) castedComp;
5262#else
5263 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
5264#endif
5265
5266 if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL))
5267 return;
5268 if ((comp == NULL) || (comp->test == NULL) || (comp->comp == NULL)) {
5269 xsltTransformError(ctxt, NULL, inst,
5270 "Internal error in xsltIf(): "
5271 "The XSLT 'if' instruction was not compiled.\n");
5272 return;
5273 }
5274
5275#ifdef WITH_XSLT_DEBUG_PROCESS
5277 "xsltIf: test %s\n", comp->test));
5278#endif
5279
5280#ifdef XSLT_FAST_IF
5281 {
5282 xmlDocPtr oldLocalFragmentTop = ctxt->localRVT;
5283
5284 res = xsltPreCompEvalToBoolean(ctxt, contextNode, comp);
5285
5286 /*
5287 * Cleanup fragments created during evaluation of the
5288 * "select" expression.
5289 */
5290 if (oldLocalFragmentTop != ctxt->localRVT)
5291 xsltReleaseLocalRVTs(ctxt, oldLocalFragmentTop);
5292 }
5293
5294#ifdef WITH_XSLT_DEBUG_PROCESS
5296 "xsltIf: test evaluate to %d\n", res));
5297#endif
5298
5299 if (res == -1) {
5300 ctxt->state = XSLT_STATE_STOPPED;
5301 goto error;
5302 }
5303 if (res == 1) {
5304 /*
5305 * Instantiate the sequence constructor of xsl:if.
5306 */
5308 contextNode, inst->children, NULL);
5309 }
5310
5311#else /* XSLT_FAST_IF */
5312 {
5313 /*
5314 * OLD CODE:
5315 */
5316 xmlXPathObjectPtr xpobj = xsltPreCompEval(ctxt, contextNode, comp);
5317 if (xpobj != NULL) {
5318 if (xpobj->type != XPATH_BOOLEAN)
5319 xpobj = xmlXPathConvertBoolean(xpobj);
5320 if (xpobj->type == XPATH_BOOLEAN) {
5321 res = xpobj->boolval;
5322
5323#ifdef WITH_XSLT_DEBUG_PROCESS
5325 "xsltIf: test evaluate to %d\n", res));
5326#endif
5327 if (res) {
5329 contextNode, inst->children, NULL);
5330 }
5331 } else {
5332
5333#ifdef WITH_XSLT_DEBUG_PROCESS
5336 "xsltIf: test didn't evaluate to a boolean\n"));
5337#endif
5338 ctxt->state = XSLT_STATE_STOPPED;
5339 }
5340 xmlXPathFreeObject(xpobj);
5341 } else {
5342 ctxt->state = XSLT_STATE_STOPPED;
5343 }
5344 }
5345#endif /* else of XSLT_FAST_IF */
5346
5347error:
5348 return;
5349}
static void xsltReleaseLocalRVTs(xsltTransformContextPtr ctxt, xmlDocPtr base)
Definition: transform.c:2226
@ XSLT_TRACE_IF
Definition: xsltutils.h:112

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltLocalVariablePop()

XSLTPUBFUN void XSLTCALL xsltLocalVariablePop ( xsltTransformContextPtr  ctxt,
int  limitNr,
int  level 
)

xsltLocalVariablePop: @ctxt: the transformation context @limitNr: number of variables which should remain @level: the depth in the xsl:template's tree

Pops all variable values at the given @depth from the stack.

Returns the stored variable value NOTE: This is an internal routine and should not be called by users!

Definition at line 150 of file transform.c.

151{
153
154 if (ctxt->varsNr <= 0)
155 return;
156
157 do {
158 if (ctxt->varsNr <= limitNr)
159 break;
160 variable = ctxt->varsTab[ctxt->varsNr - 1];
161 if (variable->level <= level)
162 break;
163 if (variable->level >= 0)
165 ctxt->varsNr--;
166 } while (ctxt->varsNr != 0);
167 if (ctxt->varsNr > 0)
168 ctxt->vars = ctxt->varsTab[ctxt->varsNr - 1];
169 else
170 ctxt->vars = NULL;
171}
GLint level
Definition: gl.h:1546
GLenum GLenum variable
Definition: glext.h:9031
xsltStackElemPtr vars

Referenced by xsltApplyOneTemplate(), xsltApplySequenceConstructor(), and xsltApplyStylesheetInternal().

◆ xsltLocalVariablePush()

XSLTPUBFUN int XSLTCALL xsltLocalVariablePush ( xsltTransformContextPtr  ctxt,
xsltStackElemPtr  variable,
int  level 
)

xsltLocalVariablePush: @ctxt: the transformation context @variable: variable to be pushed to the variable stack @level: new value for variable's level

Places the variable onto the local variable stack

Returns: 0 for success, -1 for any error NOTE: This is an internal routine and should not be called by users!

Definition at line 2188 of file transform.c.

2191{
2192 if (ctxt->varsMax == 0) {
2193 ctxt->varsMax = 10;
2194 ctxt->varsTab =
2196 sizeof(ctxt->varsTab[0]));
2197 if (ctxt->varsTab == NULL) {
2198 xmlGenericError(xmlGenericErrorContext, "malloc failed !\n");
2199 return (-1);
2200 }
2201 }
2202 if (ctxt->varsNr >= ctxt->varsMax) {
2203 ctxt->varsMax *= 2;
2204 ctxt->varsTab =
2206 ctxt->varsMax *
2207 sizeof(ctxt->varsTab[0]));
2208 if (ctxt->varsTab == NULL) {
2209 xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
2210 return (-1);
2211 }
2212 }
2213 ctxt->varsTab[ctxt->varsNr++] = variable;
2214 ctxt->vars = variable;
2215 variable->level = level;
2216 return(0);
2217}
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337

Referenced by xsltApplyOneTemplate(), and xsltApplyXSLTTemplate().

◆ xsltNewTransformContext()

XSLTPUBFUN xsltTransformContextPtr XSLTCALL xsltNewTransformContext ( xsltStylesheetPtr  style,
xmlDocPtr  doc 
)

Export context to users.

xsltNewTransformContext: @style: a parsed XSLT stylesheet @doc: the input document

Create a new XSLT TransformContext

Returns the newly allocated xsltTransformContextPtr or NULL in case of error

Definition at line 536 of file transform.c.

536 {
538 xsltDocumentPtr docu;
539 int i;
540
542
544 if (cur == NULL) {
546 "xsltNewTransformContext : malloc failed\n");
547 return(NULL);
548 }
549 memset(cur, 0, sizeof(xsltTransformContext));
550
551 cur->cache = xsltTransformCacheCreate();
552 if (cur->cache == NULL)
553 goto internal_err;
554 /*
555 * setup of the dictionary must be done early as some of the
556 * processing later like key handling may need it.
557 */
558 cur->dict = xmlDictCreateSub(style->dict);
559 cur->internalized = ((style->internalized) && (cur->dict != NULL));
560#ifdef WITH_XSLT_DEBUG
562 "Creating sub-dictionary from stylesheet for transformation\n");
563#endif
564
565 /*
566 * initialize the template stack
567 */
568 cur->templTab = (xsltTemplatePtr *)
569 xmlMalloc(10 * sizeof(xsltTemplatePtr));
570 if (cur->templTab == NULL) {
572 "xsltNewTransformContext: out of memory\n");
573 goto internal_err;
574 }
575 cur->templNr = 0;
576 cur->templMax = 5;
577 cur->templ = NULL;
578 cur->maxTemplateDepth = xsltMaxDepth;
579
580 /*
581 * initialize the variables stack
582 */
583 cur->varsTab = (xsltStackElemPtr *)
584 xmlMalloc(10 * sizeof(xsltStackElemPtr));
585 if (cur->varsTab == NULL) {
587 "xsltNewTransformContext: out of memory\n");
588 goto internal_err;
589 }
590 cur->varsNr = 0;
591 cur->varsMax = 10;
592 cur->vars = NULL;
593 cur->varsBase = 0;
594 cur->maxTemplateVars = xsltMaxVars;
595
596 /*
597 * the profiling stack is not initialized by default
598 */
599 cur->profTab = NULL;
600 cur->profNr = 0;
601 cur->profMax = 0;
602 cur->prof = 0;
603
604 cur->style = style;
605 cur->xpathCtxt = xmlXPathNewContext(doc);
606 if (cur->xpathCtxt == NULL) {
608 "xsltNewTransformContext : xmlXPathNewContext failed\n");
609 goto internal_err;
610 }
611 /*
612 * Create an XPath cache.
613 */
614 if (xmlXPathContextSetCache(cur->xpathCtxt, 1, -1, 0) == -1)
615 goto internal_err;
616 /*
617 * Initialize the extras array
618 */
619 if (style->extrasNr != 0) {
620 cur->extrasMax = style->extrasNr + 20;
621 cur->extras = (xsltRuntimeExtraPtr)
622 xmlMalloc(cur->extrasMax * sizeof(xsltRuntimeExtra));
623 if (cur->extras == NULL) {
625 "xsltNewTransformContext: out of memory\n");
626 goto internal_err;
627 }
628 cur->extrasNr = style->extrasNr;
629 for (i = 0;i < cur->extrasMax;i++) {
630 cur->extras[i].info = NULL;
631 cur->extras[i].deallocate = NULL;
632 cur->extras[i].val.ptr = NULL;
633 }
634 } else {
635 cur->extras = NULL;
636 cur->extrasNr = 0;
637 cur->extrasMax = 0;
638 }
639
642 cur->xpathCtxt->nsHash = style->nsHash;
643 /*
644 * Initialize the registered external modules
645 */
647 /*
648 * Setup document element ordering for later efficiencies
649 * (bug 133289)
650 */
652 xmlXPathOrderDocElems(doc);
653 /*
654 * Must set parserOptions before calling xsltNewDocument
655 * (bug 164530)
656 */
657 cur->parserOptions = XSLT_PARSE_OPTIONS;
658 docu = xsltNewDocument(cur, doc);
659 if (docu == NULL) {
661 "xsltNewTransformContext : xsltNewDocument failed\n");
662 goto internal_err;
663 }
664 docu->main = 1;
665 cur->document = docu;
666 cur->inst = NULL;
667 cur->outputFile = NULL;
669 cur->debugStatus = xslDebugStatus;
670 cur->traceCode = (unsigned long*) &xsltDefaultTrace;
671 cur->xinclude = xsltGetXIncludeDefault();
672 cur->keyInitLevel = 0;
673
674 return(cur);
675
676internal_err:
677 if (cur != NULL)
679 return(NULL);
680}
int xsltInitCtxtExts(xsltTransformContextPtr ctxt)
Definition: extensions.c:1016
void xsltInitGlobals(void)
Definition: extensions.c:2257
xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void)
Definition: security.c:163
static unsigned long xsltDefaultTrace
Definition: transform.c:441
void xsltFreeTransformContext(xsltTransformContextPtr ctxt)
Definition: transform.c:689
int xsltMaxDepth
Definition: transform.c:35
static xsltTransformCachePtr xsltTransformCacheCreate(void)
Definition: transform.c:471
int xsltGetXIncludeDefault(void)
Definition: transform.c:437
int xsltMaxVars
Definition: transform.c:36
xsltDocumentPtr xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc)
Definition: documents.c:127
#define XSLT_REGISTER_FUNCTION_LOOKUP(ctxt)
Definition: functions.h:27
XMLPUBFUN xmlDictPtr XMLCALL xmlDictCreateSub(xmlDictPtr sub)
Definition: dict.c:624
#define XSLT_REGISTER_VARIABLE_LOOKUP(ctxt)
Definition: variables.h:30
xsltTransformContext * xsltTransformContextPtr
xsltRuntimeExtra * xsltRuntimeExtraPtr
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54

Referenced by xsltApplyStylesheetInternal().

◆ xsltNumber()

XSLTPUBFUN void XSLTCALL xsltNumber ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltNumber: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the xslt number node @castedComp: precomputed information

Process the xslt number node on the source node

Definition at line 4553 of file transform.c.

4555{
4556#ifdef XSLT_REFACTORED
4557 xsltStyleItemNumberPtr comp = (xsltStyleItemNumberPtr) castedComp;
4558#else
4559 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4560#endif
4561 xmlXPathContextPtr xpctxt;
4562 xmlNsPtr *oldXPNamespaces;
4563 int oldXPNsNr;
4564
4565 if (comp == NULL) {
4566 xsltTransformError(ctxt, NULL, inst,
4567 "xsl:number : compilation failed\n");
4568 return;
4569 }
4570
4571 if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
4572 return;
4573
4574 comp->numdata.doc = inst->doc;
4575 comp->numdata.node = inst;
4576
4577 xpctxt = ctxt->xpathCtxt;
4578 oldXPNsNr = xpctxt->nsNr;
4579 oldXPNamespaces = xpctxt->namespaces;
4580
4581#ifdef XSLT_REFACTORED
4582 if (comp->inScopeNs != NULL) {
4583 xpctxt->namespaces = comp->inScopeNs->list;
4584 xpctxt->nsNr = comp->inScopeNs->xpathNumber;
4585 } else {
4586 xpctxt->namespaces = NULL;
4587 xpctxt->nsNr = 0;
4588 }
4589#else
4590 xpctxt->namespaces = comp->nsList;
4591 xpctxt->nsNr = comp->nsNr;
4592#endif
4593
4594 xsltNumberFormat(ctxt, &comp->numdata, node);
4595
4596 xpctxt->nsNr = oldXPNsNr;
4597 xpctxt->namespaces = oldXPNamespaces;
4598}
void xsltNumberFormat(xsltTransformContextPtr ctxt, xsltNumberDataPtr data, xmlNodePtr node)
Definition: numbers.c:728

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltProcessingInstruction()

XSLTPUBFUN void XSLTCALL xsltProcessingInstruction ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltProcessingInstruction: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the xslt processing-instruction node @castedComp: precomputed information

Process the xslt processing-instruction node on the source node

Definition at line 4269 of file transform.c.

4270 {
4271#ifdef XSLT_REFACTORED
4272 xsltStyleItemPIPtr comp = (xsltStyleItemPIPtr) castedComp;
4273#else
4274 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4275#endif
4276 const xmlChar *name;
4277 xmlChar *value = NULL;
4278 xmlNodePtr pi;
4279
4280
4281 if (ctxt->insert == NULL)
4282 return;
4283 if (comp->has_name == 0)
4284 return;
4285 if (comp->name == NULL) {
4286 name = xsltEvalAttrValueTemplate(ctxt, inst,
4287 (const xmlChar *)"name", NULL);
4288 if (name == NULL) {
4289 xsltTransformError(ctxt, NULL, inst,
4290 "xsl:processing-instruction : name is missing\n");
4291 goto error;
4292 }
4293 } else {
4294 name = comp->name;
4295 }
4296 /* TODO: check that it's both an an NCName and a PITarget. */
4297
4298
4299 value = xsltEvalTemplateString(ctxt, node, inst);
4300 if (xmlStrstr(value, BAD_CAST "?>") != NULL) {
4301 xsltTransformError(ctxt, NULL, inst,
4302 "xsl:processing-instruction: '?>' not allowed within PI content\n");
4303 goto error;
4304 }
4305#ifdef WITH_XSLT_DEBUG_PROCESS
4306 if (value == NULL) {
4308 "xsltProcessingInstruction: %s empty\n", name));
4309 } else {
4311 "xsltProcessingInstruction: %s content %s\n", name, value));
4312 }
4313#endif
4314
4315 pi = xmlNewDocPI(ctxt->insert->doc, name, value);
4316 pi = xsltAddChild(ctxt->insert, pi);
4317
4318error:
4319 if ((name != NULL) && (name != comp->name))
4320 xmlFree((xmlChar *) name);
4321 if (value != NULL)
4322 xmlFree(value);
4323}
static refpint_t pi[]
Definition: server.c:96
@ XSLT_TRACE_PI
Definition: xsltutils.h:106

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltProcessOneNode()

XSLTPUBFUN void XSLTCALL xsltProcessOneNode ( xsltTransformContextPtr  ctxt,
xmlNodePtr  contextNode,
xsltStackElemPtr  withParams 
)

xsltProcessOneNode: @ctxt: a XSLT process context @contextNode: the "current node" in the source tree @withParams: extra parameters (e.g. xsl:with-param) passed to the template if any

Process the source node.

Definition at line 2064 of file transform.c.

2066{
2067 xsltTemplatePtr templ;
2068 xmlNodePtr oldNode;
2069
2070 templ = xsltGetTemplate(ctxt, contextNode, NULL);
2071 /*
2072 * If no template is found, apply the default rule.
2073 */
2074 if (templ == NULL) {
2075#ifdef WITH_XSLT_DEBUG_PROCESS
2076 if (contextNode->type == XML_DOCUMENT_NODE) {
2078 "xsltProcessOneNode: no template found for /\n"));
2079 } else if (contextNode->type == XML_CDATA_SECTION_NODE) {
2081 "xsltProcessOneNode: no template found for CDATA\n"));
2082 } else if (contextNode->type == XML_ATTRIBUTE_NODE) {
2084 "xsltProcessOneNode: no template found for attribute %s\n",
2085 ((xmlAttrPtr) contextNode)->name));
2086 } else {
2088 "xsltProcessOneNode: no template found for %s\n", contextNode->name));
2089 }
2090#endif
2091 oldNode = ctxt->node;
2092 ctxt->node = contextNode;
2093 xsltDefaultProcessOneNode(ctxt, contextNode, withParams);
2094 ctxt->node = oldNode;
2095 return;
2096 }
2097
2098 if (contextNode->type == XML_ATTRIBUTE_NODE) {
2099 xsltTemplatePtr oldCurTempRule = ctxt->currentTemplateRule;
2100 /*
2101 * Set the "current template rule".
2102 */
2103 ctxt->currentTemplateRule = templ;
2104
2105#ifdef WITH_XSLT_DEBUG_PROCESS
2107 "xsltProcessOneNode: applying template '%s' for attribute %s\n",
2108 templ->match, contextNode->name));
2109#endif
2110 xsltApplyXSLTTemplate(ctxt, contextNode, templ->content, templ, withParams);
2111
2112 ctxt->currentTemplateRule = oldCurTempRule;
2113 } else {
2114 xsltTemplatePtr oldCurTempRule = ctxt->currentTemplateRule;
2115 /*
2116 * Set the "current template rule".
2117 */
2118 ctxt->currentTemplateRule = templ;
2119
2120#ifdef WITH_XSLT_DEBUG_PROCESS
2121 if (contextNode->type == XML_DOCUMENT_NODE) {
2123 "xsltProcessOneNode: applying template '%s' for /\n",
2124 templ->match));
2125 } else {
2127 "xsltProcessOneNode: applying template '%s' for %s\n",
2128 templ->match, contextNode->name));
2129 }
2130#endif
2131 xsltApplyXSLTTemplate(ctxt, contextNode, templ->content, templ, withParams);
2132
2133 ctxt->currentTemplateRule = oldCurTempRule;
2134 }
2135}
xmlChar * match
@ XSLT_TRACE_PROCESS_NODE
Definition: xsltutils.h:102

Referenced by xsltApplyStylesheetInternal(), xsltApplyTemplates(), and xsltDefaultProcessOneNode().

◆ xsltProfileStylesheet()

XSLTPUBFUN xmlDocPtr XSLTCALL xsltProfileStylesheet ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params,
FILE output 
)

xsltProfileStylesheet: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated arry of parameters names/values tuples @output: a FILE * for the profiling output

Apply the stylesheet to the document and dump the profiling to the given output.

Returns the result document or NULL in case of error

Definition at line 6163 of file transform.c.

6165{
6166 xmlDocPtr res;
6167
6169 return (res);
6170}

◆ xsltRegisterAllElement()

XSLTPUBFUN void XSLTCALL xsltRegisterAllElement ( xsltTransformContextPtr  ctxt)

xsltRegisterAllElement: @ctxt: the XPath context

Registers all default XSLT elements in this context

Definition at line 6307 of file transform.c.

6308{
6309 xsltRegisterExtElement(ctxt, (const xmlChar *) "apply-templates",
6312 xsltRegisterExtElement(ctxt, (const xmlChar *) "apply-imports",
6315 xsltRegisterExtElement(ctxt, (const xmlChar *) "call-template",
6318 xsltRegisterExtElement(ctxt, (const xmlChar *) "element",
6320 xsltElement);
6321 xsltRegisterExtElement(ctxt, (const xmlChar *) "attribute",
6324 xsltRegisterExtElement(ctxt, (const xmlChar *) "text",
6326 xsltText);
6327 xsltRegisterExtElement(ctxt, (const xmlChar *) "processing-instruction",
6330 xsltRegisterExtElement(ctxt, (const xmlChar *) "comment",
6332 xsltComment);
6333 xsltRegisterExtElement(ctxt, (const xmlChar *) "copy",
6335 xsltCopy);
6336 xsltRegisterExtElement(ctxt, (const xmlChar *) "value-of",
6338 xsltValueOf);
6339 xsltRegisterExtElement(ctxt, (const xmlChar *) "number",
6341 xsltNumber);
6342 xsltRegisterExtElement(ctxt, (const xmlChar *) "for-each",
6344 xsltForEach);
6345 xsltRegisterExtElement(ctxt, (const xmlChar *) "if",
6347 xsltIf);
6348 xsltRegisterExtElement(ctxt, (const xmlChar *) "choose",
6350 xsltChoose);
6351 xsltRegisterExtElement(ctxt, (const xmlChar *) "sort",
6353 xsltSort);
6354 xsltRegisterExtElement(ctxt, (const xmlChar *) "copy-of",
6356 xsltCopyOf);
6357 xsltRegisterExtElement(ctxt, (const xmlChar *) "message",
6360
6361 /*
6362 * Those don't have callable entry points but are registered anyway
6363 */
6364 xsltRegisterExtElement(ctxt, (const xmlChar *) "variable",
6366 xsltDebug);
6367 xsltRegisterExtElement(ctxt, (const xmlChar *) "param",
6369 xsltDebug);
6370 xsltRegisterExtElement(ctxt, (const xmlChar *) "with-param",
6372 xsltDebug);
6373 xsltRegisterExtElement(ctxt, (const xmlChar *) "decimal-format",
6375 xsltDebug);
6376 xsltRegisterExtElement(ctxt, (const xmlChar *) "when",
6378 xsltDebug);
6379 xsltRegisterExtElement(ctxt, (const xmlChar *) "otherwise",
6381 xsltDebug);
6382 xsltRegisterExtElement(ctxt, (const xmlChar *) "fallback",
6384 xsltDebug);
6385
6386}
int xsltRegisterExtElement(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *URI, xsltTransformFunction function)
Definition: extensions.c:621
void xsltDebug(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst ATTRIBUTE_UNUSED, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: extra.c:35
void xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: attributes.c:716
void xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:5361
void xsltCallTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4679
void xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4479
void xsltSort(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst, xsltElemPreCompPtr comp)
Definition: transform.c:3839
void xsltApplyImports(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: transform.c:4610
void xsltProcessingInstruction(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4269
static void xsltMessageWrapper(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: transform.c:6295
void xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4335
void xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4017
void xsltIf(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:5255
void xsltComment(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: transform.c:4225
void xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr contextNode, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: transform.c:5096
void xsltText(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr inst, xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
Definition: transform.c:3980
void xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:3861
void xsltNumber(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4553
void xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr castedComp)
Definition: transform.c:4782

◆ xsltRunStylesheet()

XSLTPUBFUN int XSLTCALL xsltRunStylesheet ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params,
const char output,
xmlSAXHandlerPtr  SAX,
xmlOutputBufferPtr  IObuf 
)

xsltRunStylesheet: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated array of parameters names/values tuples @output: the URL/filename ot the generated resource if available @SAX: a SAX handler for progressive callback output (not implemented yet) @IObuf: an output buffer for progressive output (not implemented yet)

Apply the stylesheet to the document and generate the output according to @output @SAX and @IObuf. It's an error to specify both @SAX and @IObuf.

NOTE: This may lead to a non-wellformed output XML wise ! NOTE: This may also result in multiple files being generated NOTE: using IObuf, the result encoding used will be the one used for creating the output buffer, use the following macro to read it from the stylesheet XSLT_GET_IMPORT_PTR(encoding, style, encoding) NOTE: using SAX, any encoding specified in the stylesheet will be lost since the interface uses only UTF8

Returns the number of bytes written to the main resource or -1 in case of error.

Definition at line 6286 of file transform.c.

6289{
6290 return(xsltRunStylesheetUser(style, doc, params, output, SAX, IObuf,
6291 NULL, NULL));
6292}
int xsltRunStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf, FILE *profile, xsltTransformContextPtr userCtxt)
Definition: transform.c:6225

◆ xsltRunStylesheetUser()

XSLTPUBFUN int XSLTCALL xsltRunStylesheetUser ( xsltStylesheetPtr  style,
xmlDocPtr  doc,
const char **  params,
const char output,
xmlSAXHandlerPtr  SAX,
xmlOutputBufferPtr  IObuf,
FILE profile,
xsltTransformContextPtr  userCtxt 
)

xsltRunStylesheetUser: @style: a parsed XSLT stylesheet @doc: a parsed XML document @params: a NULL terminated array of parameters names/values tuples @output: the URL/filename ot the generated resource if available @SAX: a SAX handler for progressive callback output (not implemented yet) @IObuf: an output buffer for progressive output (not implemented yet) @profile: profile FILE * output or NULL @userCtxt: user provided transform context

Apply the stylesheet to the document and generate the output according to @output @SAX and @IObuf. It's an error to specify both @SAX and @IObuf.

NOTE: This may lead to a non-wellformed output XML wise ! NOTE: This may also result in multiple files being generated NOTE: using IObuf, the result encoding used will be the one used for creating the output buffer, use the following macro to read it from the stylesheet XSLT_GET_IMPORT_PTR(encoding, style, encoding) NOTE: using SAX, any encoding specified in the stylesheet will be lost since the interface uses only UTF8

Returns the number of by written to the main resource or -1 in case of error.

Definition at line 6225 of file transform.c.

6229{
6230 xmlDocPtr tmp;
6231 int ret;
6232
6233 if ((output == NULL) && (SAX == NULL) && (IObuf == NULL))
6234 return (-1);
6235 if ((SAX != NULL) && (IObuf != NULL))
6236 return (-1);
6237
6238 /* unsupported yet */
6239 if (SAX != NULL) {
6240 XSLT_TODO /* xsltRunStylesheet xmlSAXHandlerPtr SAX */
6241 return (-1);
6242 }
6243
6244 tmp = xsltApplyStylesheetInternal(style, doc, params, output, profile,
6245 userCtxt);
6246 if (tmp == NULL) {
6248 "xsltRunStylesheet : run failed\n");
6249 return (-1);
6250 }
6251 if (IObuf != NULL) {
6252 /* TODO: incomplete, IObuf output not progressive */
6253 ret = xsltSaveResultTo(IObuf, tmp, style);
6254 } else {
6255 ret = xsltSaveResultToFilename(output, tmp, style, 0);
6256 }
6257 xmlFreeDoc(tmp);
6258 return (ret);
6259}
int xsltSaveResultTo(xmlOutputBufferPtr buf, xmlDocPtr result, xsltStylesheetPtr style)
Definition: xsltutils.c:1460
#define XSLT_TODO
Definition: xsltutils.h:31

Referenced by xsltRunStylesheet().

◆ xsltSetXIncludeDefault()

XSLTPUBFUN void XSLTCALL xsltSetXIncludeDefault ( int  xinclude)

XInclude default processing.

xsltSetXIncludeDefault: @xinclude: whether to do XInclude processing

Set whether XInclude should be processed on document being loaded by default

Definition at line 425 of file transform.c.

425 {
426 xsltDoXIncludeDefault = (xinclude != 0);
427}

◆ xsltSort()

XSLTPUBFUN void XSLTCALL xsltSort ( xsltTransformContextPtr  ctxt,
xmlNodePtr node  ATTRIBUTE_UNUSED,
xmlNodePtr  inst,
xsltElemPreCompPtr  comp 
)

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

function attached to xsl:sort nodes, but this should not be called directly

Definition at line 3839 of file transform.c.

3841 {
3842 if (comp == NULL) {
3843 xsltTransformError(ctxt, NULL, inst,
3844 "xsl:sort : compilation failed\n");
3845 return;
3846 }
3847 xsltTransformError(ctxt, NULL, inst,
3848 "xsl:sort : improper use this should not be reached\n");
3849}

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltText()

XSLTPUBFUN void XSLTCALL xsltText ( xsltTransformContextPtr  ctxt,
xmlNodePtr node  ATTRIBUTE_UNUSED,
xmlNodePtr  inst,
xsltElemPreCompPtr comp  ATTRIBUTE_UNUSED 
)

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

Process the xslt text node on the source node

Definition at line 3980 of file transform.c.

3981 {
3982 if ((inst->children != NULL) && (comp != NULL)) {
3983 xmlNodePtr text = inst->children;
3985
3986 while (text != NULL) {
3987 if ((text->type != XML_TEXT_NODE) &&
3988 (text->type != XML_CDATA_SECTION_NODE)) {
3989 xsltTransformError(ctxt, NULL, inst,
3990 "xsl:text content problem\n");
3991 break;
3992 }
3993 copy = xmlNewDocText(ctxt->output, text->content);
3994 if (text->type != XML_CDATA_SECTION_NODE) {
3995#ifdef WITH_XSLT_DEBUG_PARSING
3997 "Disable escaping: %s\n", text->content);
3998#endif
3999 copy->name = xmlStringTextNoenc;
4000 }
4001 copy = xsltAddChild(ctxt->insert, copy);
4002 text = text->next;
4003 }
4004 }
4005}
const WCHAR * text
Definition: package.c:1799
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocText(const xmlDoc *doc, const xmlChar *content)

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().

◆ xsltValueOf()

XSLTPUBFUN void XSLTCALL xsltValueOf ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNodePtr  inst,
xsltElemPreCompPtr  castedComp 
)

xsltValueOf: @ctxt: a XSLT process context @node: the node in the source tree. @inst: the xslt value-of node @castedComp: precomputed information

Process the xslt value-of node on the source node

Definition at line 4479 of file transform.c.

4481{
4482#ifdef XSLT_REFACTORED
4483 xsltStyleItemValueOfPtr comp = (xsltStyleItemValueOfPtr) castedComp;
4484#else
4485 xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
4486#endif
4487 xmlXPathObjectPtr res = NULL;
4488 xmlChar *value = NULL;
4489
4490 if ((ctxt == NULL) || (node == NULL) || (inst == NULL))
4491 return;
4492
4493 if ((comp == NULL) || (comp->select == NULL) || (comp->comp == NULL)) {
4494 xsltTransformError(ctxt, NULL, inst,
4495 "Internal error in xsltValueOf(): "
4496 "The XSLT 'value-of' instruction was not compiled.\n");
4497 return;
4498 }
4499
4500#ifdef WITH_XSLT_DEBUG_PROCESS
4502 "xsltValueOf: select %s\n", comp->select));
4503#endif
4504
4505 res = xsltPreCompEval(ctxt, node, comp);
4506
4507 /*
4508 * Cast the XPath object to string.
4509 */
4510 if (res != NULL) {
4511 value = xmlXPathCastToString(res);
4512 if (value == NULL) {
4513 xsltTransformError(ctxt, NULL, inst,
4514 "Internal error in xsltValueOf(): "
4515 "failed to cast an XPath object to string.\n");
4516 ctxt->state = XSLT_STATE_STOPPED;
4517 goto error;
4518 }
4519 if (value[0] != 0) {
4520 xsltCopyTextString(ctxt, ctxt->insert, value, comp->noescape);
4521 }
4522 } else {
4523 xsltTransformError(ctxt, NULL, inst,
4524 "XPath evaluation returned no result.\n");
4525 ctxt->state = XSLT_STATE_STOPPED;
4526 goto error;
4527 }
4528
4529#ifdef WITH_XSLT_DEBUG_PROCESS
4530 if (value) {
4532 "xsltValueOf: result '%s'\n", value));
4533 }
4534#endif
4535
4536error:
4537 if (value != NULL)
4538 xmlFree(value);
4539 if (res != NULL)
4540 xmlXPathFreeObject(res);
4541}
@ XSLT_TRACE_VALUE_OF
Definition: xsltutils.h:108

Referenced by xsltNewStylePreComp(), and xsltRegisterAllElement().