19#define WITH_XSLT_DEBUG_PARSING
31#define XSLT_ELEMENT_CATEGORY_XSLT 0
32#define XSLT_ELEMENT_CATEGORY_EXTENSION 1
33#define XSLT_ELEMENT_CATEGORY_LRE 2
52const xmlChar *xsltXSLTTextMarker = (
const xmlChar *)
"XSLT Text Element";
58const xmlChar *xsltXSLTAttrMarker = (
const xmlChar *)
"LRE XSLT Attr";
62#ifdef XSLT_LOCALE_WINAPI
69#ifndef LIBXML_DEBUG_ENABLED
79#define IS_BLANK(c) (((c) == 0x20) || ((c) == 0x09) || ((c) == 0xA) || \
85#define IS_BLANK_NODE(n) \
86 (((n)->type == XML_TEXT_NODE) && (xsltIsBlank((n)->content)))
105 "The XSLT-element '%s' is not allowed at this position.\n",
109 "The element '%s' is not allowed at this position.\n",
114#ifdef XSLT_REFACTORED
131 if (
style->exclPrefixMax == 0) {
132 style->exclPrefixMax = 4;
133 style->exclPrefixTab =
135 sizeof(
style->exclPrefixTab[0]));
142 for (
i = 0;
i <
style->exclPrefixNr;
i++) {
146 if (
style->exclPrefixNr >=
style->exclPrefixMax) {
147 style->exclPrefixMax *= 2;
148 style->exclPrefixTab =
150 style->exclPrefixMax *
151 sizeof(
style->exclPrefixTab[0]));
159 return (
style->exclPrefixNr++);
174 if (
style->exclPrefixNr <= 0)
176 style->exclPrefixNr--;
177 if (
style->exclPrefixNr > 0)
182 style->exclPrefixTab[
style->exclPrefixNr] = 0;
204#ifdef XSLT_LOCALE_WINAPI
218#ifdef XSLT_LOCALE_WINAPI
220 xsltLocaleMutex =
NULL;
254 static const xmlChar permille[4] = {0xe2, 0x80, 0xb0, 0};
317 while (iter !=
NULL) {
339 return style->decimalFormat;
370 return style->decimalFormat;
400 "xsltNewTemplate : malloc failed\n");
416 if (
template ==
NULL)
448 while (
template !=
NULL) {
450 template =
template->next;
455#ifdef XSLT_REFACTORED
458xsltFreeNsAliasList(xsltNsAliasPtr
item)
470#ifdef XSLT_REFACTORED_XSLT_NSCOMP
472xsltFreeNamespaceMap(xsltNsMapPtr
item)
485xsltNewNamespaceMapItem(xsltCompilerCtxtPtr cctxt,
498 "Internal error: (xsltNewNamespaceMapItem) "
499 "memory allocation failed.\n");
505 ret->origNsName =
ns->href;
509 if (cctxt->psData->nsMap !=
NULL)
510 ret->next = cctxt->psData->nsMap;
511 cctxt->psData->nsMap =
ret;
524xsltCompilerVarInfoFree(xsltCompilerCtxtPtr cctxt)
526 xsltVarInfoPtr ivar = cctxt->ivars, ivartmp;
541xsltCompilationCtxtFree(xsltCompilerCtxtPtr cctxt)
545#ifdef WITH_XSLT_DEBUG_PARSING
547 "Freeing compilation context\n");
549 "### Max inodes: %d\n", cctxt->maxNodeInfos);
551 "### Max LREs : %d\n", cctxt->maxLREs);
556 if (cctxt->inodeList !=
NULL) {
557 xsltCompilerNodeInfoPtr tmp,
cur = cctxt->inodeList;
564 if (cctxt->tmpList !=
NULL)
565 xsltPointerListFree(cctxt->tmpList);
566 if (cctxt->nsAliases !=
NULL)
567 xsltFreeNsAliasList(cctxt->nsAliases);
570 xsltCompilerVarInfoFree(cctxt);
583static xsltCompilerCtxtPtr
585 xsltCompilerCtxtPtr
ret;
587 ret = (xsltCompilerCtxtPtr)
xmlMalloc(
sizeof(xsltCompilerCtxt));
590 "xsltCompilerCreate: allocation of compiler "
591 "context failed.\n");
594 memset(
ret, 0,
sizeof(xsltCompilerCtxt));
596 ret->errSeverity = XSLT_ERROR_SEVERITY_ERROR;
597 ret->tmpList = xsltPointerListCreate(20);
605 xsltCompilationCtxtFree(
ret);
610xsltLREEffectiveNsNodesFree(xsltEffectiveNsPtr
first)
612 xsltEffectiveNsPtr tmp;
622xsltFreePrincipalStylesheetData(xsltPrincipalStylesheetDataPtr
data)
627 if (
data->inScopeNamespaces !=
NULL) {
629 xsltNsListContainerPtr nsi;
630 xsltPointerListPtr
list =
631 (xsltPointerListPtr)
data->inScopeNamespaces;
637 nsi = (xsltNsListContainerPtr)
list->items[
i];
642 xsltPointerListFree(
list);
646 if (
data->exclResultNamespaces !=
NULL) {
648 xsltPointerListPtr
list = (xsltPointerListPtr)
649 data->exclResultNamespaces;
652 xsltPointerListFree((xsltPointerListPtr)
list->items[
i]);
654 xsltPointerListFree(
list);
658 if (
data->extElemNamespaces !=
NULL) {
659 xsltPointerListPtr
list = (xsltPointerListPtr)
660 data->extElemNamespaces;
664 xsltPointerListFree((xsltPointerListPtr)
list->items[
i]);
666 xsltPointerListFree(
list);
669 if (
data->effectiveNs) {
670 xsltLREEffectiveNsNodesFree(
data->effectiveNs);
673#ifdef XSLT_REFACTORED_XSLT_NSCOMP
674 xsltFreeNamespaceMap(
data->nsMap);
679static xsltPrincipalStylesheetDataPtr
680xsltNewPrincipalStylesheetData(
void)
682 xsltPrincipalStylesheetDataPtr
ret;
684 ret = (xsltPrincipalStylesheetDataPtr)
685 xmlMalloc(
sizeof(xsltPrincipalStylesheetData));
688 "xsltNewPrincipalStylesheetData: memory allocation failed.\n");
691 memset(
ret, 0,
sizeof(xsltPrincipalStylesheetData));
696 ret->inScopeNamespaces = xsltPointerListCreate(-1);
697 if (
ret->inScopeNamespaces ==
NULL)
702 ret->exclResultNamespaces = xsltPointerListCreate(-1);
703 if (
ret->exclResultNamespaces ==
NULL)
708 ret->extElemNamespaces = xsltPointerListCreate(-1);
709 if (
ret->extElemNamespaces ==
NULL)
736 "xsltNewStylesheet : malloc failed\n");
742 ret->omitXmlDeclaration = -1;
743 ret->standalone = -1;
748 ret->exclPrefixNr = 0;
749 ret->exclPrefixMax = 0;
753 ret->internalized = 1;
754 ret->literal_result = 0;
755 ret->forwards_compatible = 0;
757#ifdef WITH_XSLT_DEBUG
759 "creating dictionary for stylesheet\n");
765 ret->xpathCtxt = xmlXPathNewContext(
NULL);
768 "xsltNewStylesheet: xmlXPathNewContext failed\n");
771 if (xmlXPathContextSetCache(
ret->xpathCtxt, 1, -1, 0) == -1)
811 return(
style->extrasNr++);
835 "xsltAllocateExtraCtxt: out of memory\n");
852 "xsltAllocateExtraCtxt: out of memory\n");
856 for (
i = ctxt->
extrasNr;i < ctxt->extrasMax;
i++) {
901 if ((doc ==
NULL) || (rootElem ==
NULL) ||
903 (doc != rootElem->
doc))
955#ifdef XSLT_REFACTORED
962#ifdef XSLT_REFACTORED_XSLT_NSCOMP
967 XSLT_HAS_INTERNAL_NSMAP(
style))
969 xsltRestoreDocumentNamespaces(XSLT_GET_INTERNAL_NSMAP(
style),
1029#ifdef XSLT_REFACTORED
1035 if (
style->principalData) {
1036 xsltFreePrincipalStylesheetData(
style->principalData);
1049#ifdef WITH_XSLT_DEBUG
1051 "freeing dictionary from stylesheet\n");
1056 xmlXPathFreeContext(
style->xpathCtxt);
1068#ifdef XSLT_REFACTORED
1114 for (
i = 0;
i <
style->exclPrefixNr;
i++) {
1124 "xsltGetInheritedNsList : out of memory!\n");
1132 for (
i = 0;
i < nbns;
i++) {
1133 if ((
cur->prefix ==
ret[
i]->prefix) ||
1138 if (nbns >= maxns) {
1146 "xsltGetInheritedNsList : realloc failed!\n");
1160#ifdef WITH_XSLT_DEBUG_PARSING
1162 "template has %d inherited namespaces\n", nbns);
1164 template->inheritedNsNr = nbns;
1165 template->inheritedNs =
ret;
1195 style->version = prop;
1202 style->encoding = prop;
1225 }
else if (URI ==
NULL) {
1229 style->method = prop;
1232 "invalid value for method: %s\n", prop);
1237 style->method = prop;
1246 style->doctypeSystem = prop;
1253 style->doctypePublic = prop;
1259 style->standalone = 1;
1261 style->standalone = 0;
1264 "invalid value for standalone: %s\n", prop);
1278 "invalid value for indent: %s\n", prop);
1287 style->omitXmlDeclaration = 1;
1289 style->omitXmlDeclaration = 0;
1292 "invalid value for omit-xml-declaration: %s\n",
1301 if (elements !=
NULL) {
1318#ifdef WITH_XSLT_DEBUG_PARSING
1320 "add cdata section output element %s\n",
1325 "Attribute 'cdata-section-elements': The value "
1326 "'%s' is not a valid QName.\n",
element);
1342 "Attribute 'cdata-section-elements': "
1343 "Not a valid QName.\n");
1374 if (
style->mediaType)
1376 style->mediaType = prop;
1414 if (xmlValidateQName(prop, 0) != 0) {
1416 "xsl:decimal-format: Invalid QName '%s'.\n", prop);
1432 "xsltParseStylestyleDecimalFormat: %s already exists\n", prop);
1440 "xsltParseStylestyleDecimalFormat: failed creating new decimal-format\n");
1446 for (iter =
style->decimalFormat; iter->
next; iter = iter->
next)
1455 format->decimalPoint = prop;
1473 format->minusSign = prop;
1497 format->zeroDigit = prop;
1509 format->patternSeparator = prop;
1534 if (elements ==
NULL) {
1536 "xsltParseStylesheetPreserveSpace: missing elements attribute\n");
1555#ifdef WITH_XSLT_DEBUG_PARSING
1557 "add preserved space element %s\n",
element);
1560 style->stripAll = -1;
1582#ifdef XSLT_REFACTORED
1610 (
const xmlChar *)
"extension-element-prefixes",
NULL);
1621 while (*prefix != 0) {
1622 while (
IS_BLANK(*prefix)) prefix++;
1637 "xsl:extension-element-prefix : undefined namespace %s\n",
1641#ifdef WITH_XSLT_DEBUG_PARSING
1643 "add extension prefix %s\n", prefix);
1673 if (elements ==
NULL) {
1675 "xsltParseStylesheetStripSpace: missing elements attribute\n");
1694#ifdef WITH_XSLT_DEBUG_PARSING
1696 "add stripped space element %s\n",
element);
1699 style->stripAll = 1;
1721#ifdef XSLT_REFACTORED
1747 (
const xmlChar *)
"exclude-result-prefixes",
NULL);
1757 while (*prefix != 0) {
1758 while (
IS_BLANK(*prefix)) prefix++;
1773 "xsl:exclude-result-prefixes : undefined namespace %s\n",
1778#ifdef WITH_XSLT_DEBUG_PARSING
1780 "exclude result prefix %s\n", prefix);
1794#ifdef XSLT_REFACTORED
1812 return (doc->
oldNs);
1818 "xsltTreeEnsureXMLDecl: Failed to allocate "
1819 "the XML namespace.\n");
1827#ifdef LIBXML_NAMESPACE_DICT
1867 ns = xsltTreeEnsureXMLDecl(doc);
1876 }
else if (prefix ==
NULL) {
1880 if ((
ns->
prefix[0] == prefix[0]) &&
1903xsltLREBuildEffectiveNs(xsltCompilerCtxtPtr cctxt,
1907 xsltNsAliasPtr
alias;
1911 if ((cctxt->nsAliases ==
NULL) || (! cctxt->hasNsAliases))
1914 alias = cctxt->nsAliases;
1931 if (
elem->doc ==
alias->docOfTargetNs) {
1947 alias->targetNs->prefix);
1966 ns = xsltTreeAcquireStoredNs(
elem->doc,
1967 alias->targetNs->href,
1968 alias->targetNs->prefix);
1972 "Internal error in "
1973 "xsltLREBuildEffectiveNs(): "
1974 "failed to acquire a stored "
1975 "ns-declaration.\n");
1976 cctxt->style->errors++;
2004 alias = cctxt->nsAliases;
2018 if (
elem->doc ==
alias->docOfTargetNs) {
2022 alias->targetNs->prefix);
2026 ns = xsltTreeAcquireStoredNs(
elem->doc,
2027 alias->targetNs->href,
2028 alias->targetNs->prefix);
2032 "Internal error in "
2033 "xsltLREBuildEffectiveNs(): "
2034 "failed to acquire a stored "
2035 "ns-declaration.\n");
2036 cctxt->style->errors++;
2074xsltLREBuildEffectiveNsNodes(xsltCompilerCtxtPtr cctxt,
2075 xsltStyleItemLRElementInfoPtr
item,
2080 xsltEffectiveNsPtr effNs, lastEffNs =
NULL;
2081 int i,
j, holdByElem;
2082 xsltPointerListPtr extElemNs = cctxt->inode->extElemNs;
2083 xsltPointerListPtr exclResultNs = cctxt->inode->exclResultNs;
2092 extElemNs = cctxt->inode->extElemNs;
2093 exclResultNs = cctxt->inode->exclResultNs;
2095 for (
i = 0;
i <
item->inScopeNs->totalNumber;
i++) {
2096 ns =
item->inScopeNs->list[
i];
2128 if (cctxt->hasNsAliases) {
2129 xsltNsAliasPtr
alias;
2133 alias = cctxt->nsAliases;
2145 goto add_effective_ns;
2150 alias = cctxt->nsAliases;
2171 for (
j = 0;
j < exclResultNs->number;
j++)
2179 for (
j = 0;
j < extElemNs->number;
j++)
2188 if (isLRE && (
elem->nsDef !=
NULL)) {
2190 tmpns =
elem->nsDef;
2196 tmpns = tmpns->
next;
2197 }
while (tmpns !=
NULL);
2205 effNs = (xsltEffectiveNsPtr)
xmlMalloc(
sizeof(xsltEffectiveNs));
2206 if (effNs ==
NULL) {
2208 "Internal error in xsltLREBuildEffectiveNs(): "
2209 "failed to allocate memory.\n");
2210 cctxt->style->errors++;
2213 if (cctxt->psData->effectiveNs ==
NULL) {
2214 cctxt->psData->effectiveNs = effNs;
2215 effNs->nextInStore =
NULL;
2217 effNs->nextInStore = cctxt->psData->effectiveNs;
2218 cctxt->psData->effectiveNs = effNs;
2223 effNs->nsName =
ns->href;
2224 effNs->holdByElem = holdByElem;
2226 if (lastEffNs ==
NULL)
2227 item->effectiveNs = effNs;
2229 lastEffNs->next = effNs;
2247xsltLREInfoCreate(xsltCompilerCtxtPtr cctxt,
2251 xsltStyleItemLRElementInfoPtr
item;
2253 if ((cctxt ==
NULL) || (cctxt->inode ==
NULL))
2256 item = (xsltStyleItemLRElementInfoPtr)
2257 xmlMalloc(
sizeof(xsltStyleItemLRElementInfo));
2260 "Internal error in xsltLREInfoCreate(): "
2261 "memory allocation failed.\n");
2262 cctxt->style->errors++;
2265 memset(
item, 0,
sizeof(xsltStyleItemLRElementInfo));
2266 item->type = XSLT_FUNC_LITERAL_RESULT_ELEMENT;
2270 item->next = cctxt->style->preComps;
2276 item->inScopeNs = cctxt->inode->inScopeNs;
2279 xsltLREBuildEffectiveNsNodes(cctxt,
item,
elem, isLRE);
2281 cctxt->inode->litResElemInfo =
item;
2282 cctxt->inode->nsChanged = 0;
2295static xsltVarInfoPtr
2296xsltCompilerVarInfoPush(xsltCompilerCtxtPtr cctxt,
2301 xsltVarInfoPtr ivar;
2303 if ((cctxt->ivar !=
NULL) && (cctxt->ivar->next !=
NULL)) {
2304 ivar = cctxt->ivar->next;
2305 }
else if ((cctxt->ivar ==
NULL) && (cctxt->ivars !=
NULL)) {
2306 ivar = cctxt->ivars;
2308 ivar = (xsltVarInfoPtr)
xmlMalloc(
sizeof(xsltVarInfo));
2311 "xsltParseInScopeVarPush: xmlMalloc() failed!\n");
2312 cctxt->style->errors++;
2316 if (cctxt->ivars ==
NULL) {
2317 cctxt->ivars = ivar;
2320 cctxt->ivar->
next = ivar;
2321 ivar->prev = cctxt->ivar;
2326 ivar->depth = cctxt->depth;
2328 ivar->nsName = nsName;
2340xsltCompilerVarInfoPop(xsltCompilerCtxtPtr cctxt)
2343 while ((cctxt->ivar !=
NULL) &&
2344 (cctxt->ivar->depth > cctxt->depth))
2346 cctxt->ivar = cctxt->ivar->prev;
2361static xsltCompilerNodeInfoPtr
2364 xsltCompilerNodeInfoPtr
inode, iprev;
2366 if ((cctxt->inode !=
NULL) && (cctxt->inode->next !=
NULL)) {
2367 inode = cctxt->inode->next;
2368 }
else if ((cctxt->inode ==
NULL) && (cctxt->inodeList !=
NULL)) {
2369 inode = cctxt->inodeList;
2374 inode = (xsltCompilerNodeInfoPtr)
2375 xmlMalloc(
sizeof(xsltCompilerNodeInfo));
2378 "xsltCompilerNodePush: malloc failed.\n");
2382 if (cctxt->inodeList ==
NULL)
2383 cctxt->inodeList =
inode;
2385 cctxt->inodeLast->next =
inode;
2386 inode->prev = cctxt->inodeLast;
2388 cctxt->inodeLast =
inode;
2389 cctxt->maxNodeInfos++;
2390 if (cctxt->inode ==
NULL) {
2391 cctxt->inode =
inode;
2396 xsltLREInfoCreate(cctxt,
NULL, 0);
2400 cctxt->inode =
inode;
2407 inode->depth = cctxt->depth;
2409 inode->category = XSLT_ELEMENT_CATEGORY_XSLT;
2412 inode->curChildType = 0;
2413 inode->extContentHandled = 0;
2417 iprev =
inode->prev;
2424 inode->inScopeNs = iprev->inScopeNs;
2428 inode->litResElemInfo = iprev->litResElemInfo;
2429 inode->nsChanged = iprev->nsChanged;
2433 inode->exclResultNs = iprev->exclResultNs;
2437 inode->extElemNs = iprev->extElemNs;
2441 inode->preserveWhitespace = iprev->preserveWhitespace;
2445 inode->forwardsCompat = iprev->forwardsCompat;
2450 inode->preserveWhitespace = 0;
2451 inode->forwardsCompat = 0;
2468 if (cctxt->inode ==
NULL) {
2470 "xsltCompilerNodePop: Top-node mismatch.\n");
2477 if (cctxt->inode->node !=
node) {
2479 "xsltCompilerNodePop: Node mismatch.\n");
2482 if (cctxt->inode->depth != cctxt->depth) {
2484 "xsltCompilerNodePop: Depth mismatch.\n");
2491 if ((cctxt->ivar) && (cctxt->ivar->depth > cctxt->depth))
2492 xsltCompilerVarInfoPop(cctxt);
2494 cctxt->inode = cctxt->inode->prev;
2495 if (cctxt->inode !=
NULL)
2496 cctxt->inode->curChildType = 0;
2508 nsName =
node->ns->href;
2518 if (cctxt->inode->node) {
2520 infname = cctxt->inode->node->
name;
2521 if (cctxt->inode->node->ns !=
NULL)
2522 infnsName = cctxt->inode->node->ns->href;
2534 "xsltCompilerNodePop: Given : '%s' URI '%s'\n",
2537 "xsltCompilerNodePop: Expected: '%s' URI '%s'\n",
2538 infname, infnsName);
2552static xsltNsListContainerPtr
2553xsltCompilerBuildInScopeNsList(xsltCompilerCtxtPtr cctxt,
xmlNodePtr node)
2555 xsltNsListContainerPtr nsi =
NULL;
2570 nsi = (xsltNsListContainerPtr)
2574 "xsltCompilerBuildInScopeNsList: "
2575 "malloc failed!\n");
2578 memset(nsi, 0,
sizeof(xsltNsListContainer));
2581 if (nsi->list ==
NULL) {
2583 "xsltCompilerBuildInScopeNsList: "
2584 "malloc failed!\n");
2587 nsi->list[0] =
NULL;
2592 for (
i = 0;
i < nsi->totalNumber;
i++) {
2593 if ((
ns->
prefix == nsi->list[
i]->prefix) ||
2597 if (
i >= nsi->totalNumber) {
2598 if (nsi->totalNumber +1 >= maxns) {
2603 if (nsi->list ==
NULL) {
2605 "xsltCompilerBuildInScopeNsList: "
2606 "realloc failed!\n");
2610 nsi->list[nsi->totalNumber++] =
ns;
2611 nsi->list[nsi->totalNumber] =
NULL;
2624 nsi->xpathNumber = nsi->totalNumber;
2625 for (
i = 0;
i < nsi->totalNumber;
i++) {
2626 if (nsi->list[
i]->prefix ==
NULL) {
2628 nsi->list[
i] = nsi->list[nsi->totalNumber-1];
2629 nsi->list[nsi->totalNumber-1] =
ns;
2637 if (xsltPointerListAddSize(
2638 (xsltPointerListPtr)cctxt->psData->inScopeNamespaces,
2639 (
void *) nsi, 5) == -1)
2644 "xsltCompilerBuildInScopeNsList: failed to add ns-info.\n");
2650 if (cctxt->inode !=
NULL)
2651 cctxt->inode->nsChanged = 1;
2658 cctxt->style->errors++;
2663xsltParseNsPrefixList(xsltCompilerCtxtPtr cctxt,
2664 xsltPointerListPtr
list,
2695 if ((
cur[0] ==
'#') &&
2707 "No namespace binding in scope for prefix '%s'.\n",
cur);
2714 cctxt->style->errors++;
2716#ifdef WITH_XSLT_DEBUG_PARSING
2718 "resolved prefix '%s'\n",
cur);
2723 if (xsltPointerListAddSize(
list,
2725 ns->href, -1), 5) == -1)
2738 cctxt->style->errors++;
2753static xsltPointerListPtr
2754xsltCompilerUtilsCreateMergedList(xsltPointerListPtr
first,
2755 xsltPointerListPtr second)
2757 xsltPointerListPtr
ret;
2765 num += second->number;
2768 ret = xsltPointerListCreate(
num);
2776 first->number *
sizeof(
void *));
2777 if ((second !=
NULL) && (second->number != 0))
2779 second->number *
sizeof(
void *));
2780 }
else if ((second !=
NULL) && (second->number != 0))
2781 memcpy(
ret->items, (
void *) second->items,
2782 second->number *
sizeof(
void *));
2797static xsltPointerListPtr
2798xsltParseExclResultPrefixes(xsltCompilerCtxtPtr cctxt,
xmlNodePtr node,
2799 xsltPointerListPtr def,
2809 if (instrCategory == XSLT_ELEMENT_CATEGORY_XSLT)
2817 if (
attr && (instrCategory == XSLT_ELEMENT_CATEGORY_LRE)) {
2821 attr->psvi = (
void *) xsltXSLTAttrMarker;
2829 "Attribute 'exclude-result-prefixes': Invalid value.\n");
2830 cctxt->style->errors++;
2834 if (xsltParseNsPrefixList(cctxt, cctxt->tmpList,
node,
2837 if (cctxt->tmpList->number == 0)
2842 list = xsltCompilerUtilsCreateMergedList(def, cctxt->tmpList);
2848 if (xsltPointerListAddSize(
2849 cctxt->psData->exclResultNamespaces,
list, 5) == -1)
2851 xsltPointerListFree(
list);
2858 if (cctxt->inode !=
NULL)
2859 cctxt->inode->nsChanged = 1;
2878static xsltPointerListPtr
2879xsltParseExtElemPrefixes(xsltCompilerCtxtPtr cctxt,
xmlNodePtr node,
2880 xsltPointerListPtr def,
2891 if (instrCategory == XSLT_ELEMENT_CATEGORY_XSLT)
2899 if (
attr && (instrCategory == XSLT_ELEMENT_CATEGORY_LRE)) {
2903 attr->psvi = (
void *) xsltXSLTAttrMarker;
2911 "Attribute 'extension-element-prefixes': Invalid value.\n");
2912 cctxt->style->errors++;
2917 if (xsltParseNsPrefixList(cctxt, cctxt->tmpList,
node,
2921 if (cctxt->tmpList->number == 0)
2926 for (
i = 0;
i < cctxt->tmpList->number;
i++)
2932 list = xsltCompilerUtilsCreateMergedList(def, cctxt->tmpList);
2938 if (xsltPointerListAddSize(
2939 cctxt->psData->extElemNamespaces,
list, 5) == -1)
2941 xsltPointerListFree(
list);
2948 if (cctxt->inode !=
NULL)
2949 cctxt->inode->nsChanged = 1;
2971xsltParseAttrXSLTVersion(xsltCompilerCtxtPtr cctxt,
xmlNodePtr node,
2980 if (instrCategory == XSLT_ELEMENT_CATEGORY_XSLT)
2988 attr->psvi = (
void *) xsltXSLTAttrMarker;
2995 "Attribute 'version': Invalid value.\n");
2996 cctxt->style->errors++;
3001 cctxt->inode->forwardsCompat = 1;
3009 if (! cctxt->hasForwardsCompat) {
3010 cctxt->hasForwardsCompat = 1;
3011 cctxt->errSeverity = XSLT_ERROR_SEVERITY_WARNING;
3013 "Warning: the attribute xsl:version specifies a value "
3014 "different from '1.0'. Switching to forwards-compatible "
3015 "mode. Only features of XSLT 1.0 are supported by this "
3017 cctxt->style->warnings++;
3018 cctxt->errSeverity = XSLT_ERROR_SEVERITY_ERROR;
3021 cctxt->inode->forwardsCompat = 0;
3024 if (
attr && (instrCategory == XSLT_ELEMENT_CATEGORY_LRE)) {
3028 attr->psvi = (
void *) xsltXSLTAttrMarker;
3034xsltParsePreprocessStylesheetTree(xsltCompilerCtxtPtr cctxt,
xmlNodePtr node)
3039 int internalize = 0, findSpaceAttr;
3040 int xsltStylesheetElemDepth;
3044 int strictWhitespace, inXSLText = 0;
3045#ifdef XSLT_REFACTORED_XSLT_NSCOMP
3046 xsltNsMapPtr nsMapItem;
3049 if ((cctxt ==
NULL) || (cctxt->style ==
NULL) ||
3057 style = cctxt->style;
3061 style->internalized = 0;
3069 if (! cctxt->simplified)
3070 xsltStylesheetElemDepth = cctxt->depth +1;
3072 xsltStylesheetElemDepth = 0;
3075 cctxt->inode->preserveWhitespace = 0;
3077 cctxt->inode->preserveWhitespace = 1;
3082 strictWhitespace = (cctxt->strict != 0) ? 1 : 0;
3084 nsNameXSLT = xsltConstNamespaceNameXSLT;
3089 if (deleteNode !=
NULL) {
3091#ifdef WITH_XSLT_DEBUG_BLANKS
3093 "xsltParsePreprocessStylesheetTree: removing node\n");
3106 xsltCompilerNodePush(cctxt,
cur);
3111 cctxt->inode->stripWhitespace = 0;
3116#ifdef XSLT_REFACTORED_XSLT_NSCOMP
3117 if (
cur->ns->href != nsNameXSLT) {
3118 nsMapItem = xsltNewNamespaceMapItem(cctxt,
3120 if (nsMapItem ==
NULL)
3122 cur->ns->href = nsNameXSLT;
3127 goto process_attributes;
3156 if ((
name[0] ==
't') && (
name[1] ==
'e') &&
3157 (
name[2] ==
'x') && (
name[3] ==
't') &&
3165 cur->psvi = (
void *) xsltXSLTTextMarker;
3172 cctxt->inode->preserveWhitespace = 1;
3179 cctxt->inode->stripWhitespace = 1;
3186 cctxt->inode->stripWhitespace = 1;
3189 if (xsltStylesheetElemDepth == cctxt->depth) {
3193 cctxt->inode->stripWhitespace = 1;
3206 if (((*
name ==
'p') || (*
name ==
's')) &&
3223 }
while (
cur->prev);
3235 if (
cur->properties !=
NULL) {
3240#ifdef XSLT_REFACTORED_XSLT_NSCOMP
3241 if ((
attr->ns) && (
attr->ns->href != nsNameXSLT) &&
3244 nsMapItem = xsltNewNamespaceMapItem(cctxt,
3246 if (nsMapItem ==
NULL)
3248 attr->ns->href = nsNameXSLT;
3257 txt =
attr->children;
3275 if ((findSpaceAttr != 0) &&
3280 (
attr->ns->prefix[0] ==
'x') &&
3281 (
attr->ns->prefix[1] ==
'm') &&
3282 (
attr->ns->prefix[2] ==
'l') &&
3283 (
attr->ns->prefix[3] == 0))
3289 cctxt->inode->preserveWhitespace = 1;
3291 cctxt->inode->preserveWhitespace = 0;
3295 "Attribute xml:space: Invalid value.\n");
3296 cctxt->style->warnings++;
3337 if ((strictWhitespace != 0) || (inXSLText != 0)) {
3341 if (textNode ==
NULL)
3357 if (textNode ==
NULL)
3379 "Invalid type of node for the XSLT data model.\n");
3380 cctxt->style->errors++;
3395 (((cctxt->inode->stripWhitespace) ||
3396 (! cctxt->inode->preserveWhitespace)) &&
3400 if (textNode !=
cur) {
3404 deleteNode = textNode;
3438 xsltCompilerNodePop(cctxt,
cur);
3450 if (deleteNode !=
NULL) {
3451#ifdef WITH_XSLT_DEBUG_PARSING
3453 "xsltParsePreprocessStylesheetTree: removing node\n");
3466#ifdef XSLT_REFACTORED
3472 int internalize = 0;
3481 style->internalized = 0;
3497 if (deleteNode !=
NULL) {
3498#ifdef WITH_XSLT_DEBUG_BLANKS
3500 "xsltPreprocessStylesheet: removing ignorable blank node\n");
3511 if ((internalize) && (
cur->properties !=
NULL)) {
3516 txt =
attr->children;
3541 for (;exclPrefixes > 0;exclPrefixes--)
3549 if ((
cur->nsDef !=
NULL) && (
style->exclPrefixNr > 0)) {
3559 for (
i = 0;
i <
style->exclPrefixNr;
i++) {
3562 style->exclPrefixTab[
i]))) {
3569 cur->nsDef =
ns->next;
3571 prev->next =
ns->next;
3589 if (exclPrefixes > 0) {
3591 for (;exclPrefixes > 0;exclPrefixes--)
3600 }
else if ((
cur->content !=
NULL) && (internalize) &&
3625 (styleelem !=
NULL) && (
cur->parent == styleelem) &&
3629 }
else if (
cur->children !=
NULL) {
3654 if (deleteNode !=
NULL) {
3655#ifdef WITH_XSLT_DEBUG_PARSING
3657 "xsltPreprocessStylesheet: removing ignorable blank node\n");
3702 "xsltGatherNamespaces: failed to create hash table\n");
3710 "Namespaces prefix %s used for multiple namespaces\n",
ns->
prefix);
3712 }
else if (URI ==
NULL) {
3714 (
void *)
ns->href,
NULL);
3716#ifdef WITH_XSLT_DEBUG_PARSING
3718 "Added namespace: %s mapped to %s\n",
ns->
prefix,
ns->href);
3756#ifdef XSLT_REFACTORED
3759xsltGetXSLTElementTypeByNode(xsltCompilerCtxtPtr cctxt,
3766 if (
node->name[0] ==
'a') {
3776 }
else if (
node->name[0] ==
'c') {
3788 }
else if (
node->name[0] ==
'd') {
3794 }
else if (
node->name[0] ==
'e') {
3798 }
else if (
node->name[0] ==
'f') {
3802 return(XSLT_FUNC_FALLBACK);
3804 }
else if (*(
node->name) ==
'i') {
3812 }
else if (*(
node->name) ==
'k') {
3816 }
else if (*(
node->name) ==
'm') {
3818 return(XSLT_FUNC_MESSAGE);
3820 }
else if (*(
node->name) ==
'n') {
3826 }
else if (*(
node->name) ==
'o') {
3828 return(XSLT_FUNC_OTHERWISE);
3832 }
else if (*(
node->name) ==
'p') {
3840 }
else if (*(
node->name) ==
's') {
3848 }
else if (
node->name[0] ==
't') {
3856 }
else if (*(
node->name) ==
'v') {
3862 }
else if (*(
node->name) ==
'w') {
3891 if (! (IS_XSLT_ELEM_FAST(
elem)))
3896 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
3897 cctxt->inode->extContentHandled = 1;
3900 xsltCompilerNodePush(cctxt,
elem);
3905 if (cctxt->inode->prev->curChildType != 0)
3906 cctxt->inode->type = cctxt->inode->prev->curChildType;
3908 cctxt->inode->type = xsltGetXSLTElementTypeByNode(cctxt,
elem);
3913 cctxt->inode->inScopeNs =
3914 xsltCompilerBuildInScopeNsList(cctxt,
elem);
3929 switch (cctxt->inode->type) {
3935 goto apply_templates;
3938 goto sequence_constructor;
3947 goto sequence_constructor;
3950 goto sequence_constructor;
3956 goto sequence_constructor;
3959 goto sequence_constructor;
3960 case XSLT_FUNC_FALLBACK:
3962 goto sequence_constructor;
3968 goto sequence_constructor;
3969 case XSLT_FUNC_OTHERWISE:
3971 goto sequence_constructor;
3972 case XSLT_FUNC_MESSAGE:
3974 goto sequence_constructor;
3983 xsltVarInfoPtr ivar = cctxt->ivar;
3987 ((xsltStyleItemParamPtr)
elem->psvi)->name) &&
3989 ((xsltStyleItemParamPtr)
elem->psvi)->ns))
3993 "Redefinition of variable or parameter '%s'.\n",
3995 cctxt->style->errors++;
3999 }
while (ivar !=
NULL);
4002 goto sequence_constructor;
4005 goto sequence_constructor;
4020 xsltVarInfoPtr ivar = cctxt->ivar;
4024 ((xsltStyleItemVariablePtr)
elem->psvi)->name) &&
4026 ((xsltStyleItemVariablePtr)
elem->psvi)->ns))
4030 "Redefinition of variable or parameter '%s'.\n",
4032 cctxt->style->errors++;
4036 }
while (ivar !=
NULL);
4039 goto sequence_constructor;
4042 goto sequence_constructor;
4045 goto sequence_constructor;
4047#ifdef WITH_XSLT_DEBUG_PARSING
4049 "xsltParseXSLTNode: Unhandled XSLT element '%s'.\n",
4053 "xsltParseXSLTNode: Internal error; "
4054 "unhandled XSLT element '%s'.\n",
elem->name);
4055 cctxt->style->errors++;
4065 if (IS_XSLT_ELEM_FAST(
child)) {
4068 xsltParseAnyXSLTElem(cctxt,
child);
4071 xsltParseAnyXSLTElem(cctxt,
child);
4088 if (IS_XSLT_ELEM_FAST(
child)) {
4091 type = xsltGetXSLTElementTypeByNode(cctxt,
child);
4094 xsltParseAnyXSLTElem(cctxt,
child);
4114 "The XSLT 'text' element must have only character "
4115 "data as content.\n");
4134 "This XSLT element must have no content.\n");
4135 cctxt->style->errors++;
4153 int nbWhen = 0, nbOtherwise = 0,
err = 0;
4156 if (IS_XSLT_ELEM_FAST(
child)) {
4159 type = xsltGetXSLTElementTypeByNode(cctxt,
child);
4168 xsltParseAnyXSLTElem(cctxt,
child);
4169 }
else if (
type == XSLT_FUNC_OTHERWISE) {
4177 "The XSLT 'choose' element must not contain "
4178 "more than one XSLT 'otherwise' element.\n");
4179 cctxt->style->errors++;
4184 cctxt->inode->curChildType = XSLT_FUNC_OTHERWISE;
4185 xsltParseAnyXSLTElem(cctxt,
child);
4197 if ((!
err) && (! nbWhen)) {
4199 "The XSLT element 'choose' must contain at least one "
4200 "XSLT element 'when'.\n");
4201 cctxt->style->errors++;
4222 IS_XSLT_ELEM_FAST(
child))
4224 if (xsltGetXSLTElementTypeByNode(cctxt,
child) ==
4228 xsltParseAnyXSLTElem(cctxt,
child);
4239 xsltParseSequenceConstructor(cctxt,
child);
4243sequence_constructor:
4248 xsltParseSequenceConstructor(cctxt,
elem->children);
4259 (((xsltStyleBasicItemVariablePtr)
elem->psvi)->name))
4261 xsltCompilerVarInfoPush(cctxt,
elem,
4262 ((xsltStyleBasicItemVariablePtr)
elem->psvi)->name,
4263 ((xsltStyleBasicItemVariablePtr)
elem->psvi)->ns);
4269 xsltCompilerNodePop(cctxt,
elem);
4273 xsltCompilerNodePop(cctxt,
elem);
4287static xsltStyleItemUknownPtr
4288xsltForwardsCompatUnkownItemCreate(xsltCompilerCtxtPtr cctxt)
4290 xsltStyleItemUknownPtr
item;
4292 item = (xsltStyleItemUknownPtr)
xmlMalloc(
sizeof(xsltStyleItemUknown));
4295 "Internal error in xsltForwardsCompatUnkownItemCreate(): "
4296 "Failed to allocate memory.\n");
4297 cctxt->style->errors++;
4300 memset(
item, 0,
sizeof(xsltStyleItemUknown));
4301 item->type = XSLT_FUNC_UNKOWN_FORWARDS_COMPAT;
4305 item->next = cctxt->style->preComps;
4325xsltParseUnknownXSLTElem(xsltCompilerCtxtPtr cctxt,
4334 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4335 cctxt->inode->extContentHandled = 1;
4337 if (cctxt->inode->forwardsCompat == 0) {
4342 "Unknown XSLT element '%s'.\n",
node->name);
4343 cctxt->style->errors++;
4356 if (cctxt->unknownItem ==
NULL) {
4360 cctxt->unknownItem = xsltForwardsCompatUnkownItemCreate(cctxt);
4361 if (cctxt->unknownItem ==
NULL) {
4366 node->psvi = cctxt->unknownItem;
4372 xsltCompilerNodePush(cctxt,
node);
4377 cctxt->inode->inScopeNs =
4378 xsltCompilerBuildInScopeNsList(cctxt,
node);
4384 IS_XSLT_ELEM_FAST(
child) &&
4387 cctxt->inode->curChildType = XSLT_FUNC_FALLBACK;
4388 xsltParseAnyXSLTElem(cctxt,
child);
4393 xsltCompilerNodePop(cctxt,
node);
4408xsltParseSequenceConstructor(xsltCompilerCtxtPtr cctxt,
xmlNodePtr cur)
4413 if (cctxt ==
NULL) {
4415 "xsltParseSequenceConstructor: Bad arguments\n");
4416 cctxt->style->errors++;
4422 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4423 cctxt->inode->extContentHandled = 1;
4455 if (deleteNode !=
NULL) {
4456#ifdef WITH_XSLT_DEBUG_BLANKS
4458 "xsltParseSequenceConstructor: removing xsl:text element\n");
4466 if (
cur->psvi == xsltXSLTTextMarker) {
4481 tmp =
cur->children;
4495 xmlAddPrevSibling(
cur, tmp);
4499 "Element 'xsl:text': Invalid type "
4500 "of node found in content.\n");
4501 cctxt->style->errors++;
4504 if (
cur->properties) {
4516 BAD_CAST "disable-output-escaping"))
4532 }
else if ((
attr->children ==
NULL) ||
4533 (
attr->children->content ==
NULL) ||
4539 "Attribute 'disable-output-escaping': "
4540 "Invalid value. Expected is "
4541 "'yes' or 'no'.\n");
4542 cctxt->style->errors++;
4549 }
else if (IS_XSLT_ELEM_FAST(
cur)) {
4559 type = xsltGetXSLTElementTypeByNode(cctxt,
cur);
4571 case XSLT_FUNC_FALLBACK:
4574 case XSLT_FUNC_MESSAGE:
4583 cctxt->inode->curChildType =
type;
4584 xsltParseAnyXSLTElem(cctxt,
cur);
4587 xsltParseUnknownXSLTElem(cctxt,
cur);
4596 xsltCompilerNodePush(cctxt,
cur);
4601 cctxt->inode->inScopeNs =
4602 xsltCompilerBuildInScopeNsList(cctxt,
cur);
4630 if (
cur->properties)
4631 cctxt->inode->extElemNs =
4632 xsltParseExtElemPrefixes(cctxt,
4633 cur, cctxt->inode->extElemNs,
4634 XSLT_ELEMENT_CATEGORY_LRE);
4639 (cctxt->inode->extElemNs !=
NULL) &&
4647 cctxt->inode->category = XSLT_ELEMENT_CATEGORY_EXTENSION;
4648 cctxt->inode->extContentHandled = 0;
4655 "Internal error in xsltParseSequenceConstructor(): "
4656 "Occupied PSVI field.\n");
4657 cctxt->style->errors++;
4661 cur->psvi = (
void *)
4699 if ((
cur->children !=
NULL) &&
4700 (cctxt->inode->extContentHandled == 0))
4706 xsltParseSequenceConstructor(cctxt,
cur->children);
4719 cctxt->inode->category = XSLT_ELEMENT_CATEGORY_LRE;
4720 if (
cur->properties !=
NULL) {
4725 cctxt->inode->exclResultNs =
4726 xsltParseExclResultPrefixes(cctxt,
cur,
4727 cctxt->inode->exclResultNs,
4728 XSLT_ELEMENT_CATEGORY_LRE);
4732 xsltParseAttrXSLTVersion(cctxt,
cur,
4733 XSLT_ELEMENT_CATEGORY_LRE);
4744 if ((
attr->psvi != xsltXSLTAttrMarker) &&
4745 IS_XSLT_ATTR_FAST(
attr))
4752 "Unknown XSLT attribute '%s'.\n",
4754 cctxt->style->errors++;
4759 attr->psvi = (
void *) xsltXSLTAttrMarker;
4768 if (cctxt->inode->nsChanged)
4769 xsltLREInfoCreate(cctxt,
cur, 1);
4770 cur->psvi = cctxt->inode->litResElemInfo;
4774 if (cctxt->hasNsAliases)
4775 xsltLREBuildEffectiveNs(cctxt,
cur);
4779 if (
cur->properties) {
4792 xsltParseSequenceConstructor(cctxt,
cur->children);
4798 xsltCompilerNodePop(cctxt,
cur);
4803 if (deleteNode !=
NULL) {
4804#ifdef WITH_XSLT_DEBUG_BLANKS
4806 "xsltParseSequenceConstructor: removing xsl:text element\n");
4837 if (XSLT_CCTXT(
style)->
inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4838 XSLT_CCTXT(
style)->inode->extContentHandled = 1;
4850 IS_XSLT_ELEM_FAST(
child) &&
4854 xsltParseAnyXSLTElem(XSLT_CCTXT(
style),
child);
4862 xsltParseSequenceConstructor(XSLT_CCTXT(
style),
child);
4892 if (
delete !=
NULL) {
4893#ifdef WITH_XSLT_DEBUG_BLANKS
4895 "xsltParseTemplateContent: removing text\n");
4918 (
const xmlChar *)
"disable-output-escaping",
4921#ifdef WITH_XSLT_DEBUG_PARSING
4923 "Disable escaping: %s\n",
text->content);
4930 "xsl:text: disable-output-escaping allows only yes or no\n");
4945 "xsltParseTemplateContent: xslt:text content problem\n");
4960 if ((
style->internalized) &&