18 #ifdef WITH_XSLT_DEBUG 19 #define WITH_XSLT_DEBUG_PARSING 27 #ifdef XSLT_REFACTORED 31 #define XSLT_ELEMENT_CATEGORY_XSLT 0 32 #define XSLT_ELEMENT_CATEGORY_EXTENSION 1 33 #define XSLT_ELEMENT_CATEGORY_LRE 2 52 const xmlChar *xsltXSLTTextMarker = (
const xmlChar *)
"XSLT Text Element";
58 const 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};
283 if (self->patternSeparator)
284 xmlFree(self->patternSeparator);
285 if (self->decimalPoint)
316 iter =
self->decimalFormat;
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 458 xsltFreeNsAliasList(xsltNsAliasPtr
item)
470 #ifdef XSLT_REFACTORED_XSLT_NSCOMP 472 xsltFreeNamespaceMap(xsltNsMapPtr
item)
485 xsltNewNamespaceMapItem(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;
524 xsltCompilerVarInfoFree(xsltCompilerCtxtPtr cctxt)
526 xsltVarInfoPtr ivar = cctxt->ivars, ivartmp;
541 xsltCompilationCtxtFree(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);
583 static 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);
610 xsltLREEffectiveNsNodesFree(xsltEffectiveNsPtr
first)
612 xsltEffectiveNsPtr tmp;
622 xsltFreePrincipalStylesheetData(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);
679 static xsltPrincipalStylesheetDataPtr
680 xsltNewPrincipalStylesheetData(
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]) &&
1903 xsltLREBuildEffectiveNs(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++;
2074 xsltLREBuildEffectiveNsNodes(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;
2247 xsltLREInfoCreate(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;
2295 static xsltVarInfoPtr
2296 xsltCompilerVarInfoPush(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;
2340 xsltCompilerVarInfoPop(xsltCompilerCtxtPtr cctxt)
2343 while ((cctxt->ivar !=
NULL) &&
2344 (cctxt->ivar->depth > cctxt->depth))
2346 cctxt->ivar = cctxt->ivar->prev;
2361 static 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);
2552 static xsltNsListContainerPtr
2553 xsltCompilerBuildInScopeNsList(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++;
2663 xsltParseNsPrefixList(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++;
2753 static xsltPointerListPtr
2754 xsltCompilerUtilsCreateMergedList(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 *));
2797 static xsltPointerListPtr
2798 xsltParseExclResultPrefixes(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;
2878 static xsltPointerListPtr
2879 xsltParseExtElemPrefixes(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;
2971 xsltParseAttrXSLTVersion(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;
3034 xsltParsePreprocessStylesheetTree(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) {
3658 if (deleteNode !=
NULL) {
3659 #ifdef WITH_XSLT_DEBUG_PARSING 3661 "xsltPreprocessStylesheet: removing ignorable blank node\n");
3706 "xsltGatherNamespaces: failed to create hash table\n");
3714 "Namespaces prefix %s used for multiple namespaces\n",
ns->
prefix);
3716 }
else if (URI ==
NULL) {
3718 (
void *)
ns->href,
NULL);
3720 #ifdef WITH_XSLT_DEBUG_PARSING 3722 "Added namespace: %s mapped to %s\n",
ns->
prefix,
ns->href);
3760 #ifdef XSLT_REFACTORED 3763 xsltGetXSLTElementTypeByNode(xsltCompilerCtxtPtr cctxt,
3770 if (
node->name[0] ==
'a') {
3780 }
else if (
node->name[0] ==
'c') {
3792 }
else if (
node->name[0] ==
'd') {
3798 }
else if (
node->name[0] ==
'e') {
3802 }
else if (
node->name[0] ==
'f') {
3806 return(XSLT_FUNC_FALLBACK);
3808 }
else if (*(
node->name) ==
'i') {
3816 }
else if (*(
node->name) ==
'k') {
3820 }
else if (*(
node->name) ==
'm') {
3822 return(XSLT_FUNC_MESSAGE);
3824 }
else if (*(
node->name) ==
'n') {
3830 }
else if (*(
node->name) ==
'o') {
3832 return(XSLT_FUNC_OTHERWISE);
3836 }
else if (*(
node->name) ==
'p') {
3844 }
else if (*(
node->name) ==
's') {
3852 }
else if (
node->name[0] ==
't') {
3860 }
else if (*(
node->name) ==
'v') {
3866 }
else if (*(
node->name) ==
'w') {
3895 if (! (IS_XSLT_ELEM_FAST(
elem)))
3900 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
3901 cctxt->inode->extContentHandled = 1;
3904 xsltCompilerNodePush(cctxt,
elem);
3909 if (cctxt->inode->prev->curChildType != 0)
3910 cctxt->inode->type = cctxt->inode->prev->curChildType;
3912 cctxt->inode->type = xsltGetXSLTElementTypeByNode(cctxt,
elem);
3917 cctxt->inode->inScopeNs =
3918 xsltCompilerBuildInScopeNsList(cctxt,
elem);
3933 switch (cctxt->inode->type) {
3939 goto apply_templates;
3942 goto sequence_constructor;
3951 goto sequence_constructor;
3954 goto sequence_constructor;
3960 goto sequence_constructor;
3963 goto sequence_constructor;
3964 case XSLT_FUNC_FALLBACK:
3966 goto sequence_constructor;
3972 goto sequence_constructor;
3973 case XSLT_FUNC_OTHERWISE:
3975 goto sequence_constructor;
3976 case XSLT_FUNC_MESSAGE:
3978 goto sequence_constructor;
3987 xsltVarInfoPtr ivar = cctxt->ivar;
3991 ((xsltStyleItemParamPtr)
elem->psvi)->name) &&
3993 ((xsltStyleItemParamPtr)
elem->psvi)->ns))
3997 "Redefinition of variable or parameter '%s'.\n",
3999 cctxt->style->errors++;
4003 }
while (ivar !=
NULL);
4006 goto sequence_constructor;
4009 goto sequence_constructor;
4024 xsltVarInfoPtr ivar = cctxt->ivar;
4028 ((xsltStyleItemVariablePtr)
elem->psvi)->name) &&
4030 ((xsltStyleItemVariablePtr)
elem->psvi)->ns))
4034 "Redefinition of variable or parameter '%s'.\n",
4036 cctxt->style->errors++;
4040 }
while (ivar !=
NULL);
4043 goto sequence_constructor;
4046 goto sequence_constructor;
4049 goto sequence_constructor;
4051 #ifdef WITH_XSLT_DEBUG_PARSING 4053 "xsltParseXSLTNode: Unhandled XSLT element '%s'.\n",
4057 "xsltParseXSLTNode: Internal error; " 4058 "unhandled XSLT element '%s'.\n",
elem->name);
4059 cctxt->style->errors++;
4069 if (IS_XSLT_ELEM_FAST(
child)) {
4072 xsltParseAnyXSLTElem(cctxt,
child);
4075 xsltParseAnyXSLTElem(cctxt,
child);
4092 if (IS_XSLT_ELEM_FAST(
child)) {
4095 type = xsltGetXSLTElementTypeByNode(cctxt,
child);
4098 xsltParseAnyXSLTElem(cctxt,
child);
4118 "The XSLT 'text' element must have only character " 4119 "data as content.\n");
4138 "This XSLT element must have no content.\n");
4139 cctxt->style->errors++;
4157 int nbWhen = 0, nbOtherwise = 0,
err = 0;
4160 if (IS_XSLT_ELEM_FAST(
child)) {
4163 type = xsltGetXSLTElementTypeByNode(cctxt,
child);
4172 xsltParseAnyXSLTElem(cctxt,
child);
4173 }
else if (
type == XSLT_FUNC_OTHERWISE) {
4181 "The XSLT 'choose' element must not contain " 4182 "more than one XSLT 'otherwise' element.\n");
4183 cctxt->style->errors++;
4188 cctxt->inode->curChildType = XSLT_FUNC_OTHERWISE;
4189 xsltParseAnyXSLTElem(cctxt,
child);
4201 if ((!
err) && (! nbWhen)) {
4203 "The XSLT element 'choose' must contain at least one " 4204 "XSLT element 'when'.\n");
4205 cctxt->style->errors++;
4226 IS_XSLT_ELEM_FAST(
child))
4228 if (xsltGetXSLTElementTypeByNode(cctxt,
child) ==
4232 xsltParseAnyXSLTElem(cctxt,
child);
4243 xsltParseSequenceConstructor(cctxt,
child);
4247 sequence_constructor:
4252 xsltParseSequenceConstructor(cctxt,
elem->children);
4263 (((xsltStyleBasicItemVariablePtr)
elem->psvi)->name))
4265 xsltCompilerVarInfoPush(cctxt,
elem,
4266 ((xsltStyleBasicItemVariablePtr)
elem->psvi)->name,
4267 ((xsltStyleBasicItemVariablePtr)
elem->psvi)->ns);
4273 xsltCompilerNodePop(cctxt,
elem);
4277 xsltCompilerNodePop(cctxt,
elem);
4291 static xsltStyleItemUknownPtr
4292 xsltForwardsCompatUnkownItemCreate(xsltCompilerCtxtPtr cctxt)
4294 xsltStyleItemUknownPtr
item;
4296 item = (xsltStyleItemUknownPtr)
xmlMalloc(
sizeof(xsltStyleItemUknown));
4299 "Internal error in xsltForwardsCompatUnkownItemCreate(): " 4300 "Failed to allocate memory.\n");
4301 cctxt->style->errors++;
4304 memset(
item, 0,
sizeof(xsltStyleItemUknown));
4305 item->type = XSLT_FUNC_UNKOWN_FORWARDS_COMPAT;
4309 item->next = cctxt->style->preComps;
4329 xsltParseUnknownXSLTElem(xsltCompilerCtxtPtr cctxt,
4338 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4339 cctxt->inode->extContentHandled = 1;
4341 if (cctxt->inode->forwardsCompat == 0) {
4346 "Unknown XSLT element '%s'.\n",
node->name);
4347 cctxt->style->errors++;
4360 if (cctxt->unknownItem ==
NULL) {
4364 cctxt->unknownItem = xsltForwardsCompatUnkownItemCreate(cctxt);
4365 if (cctxt->unknownItem ==
NULL) {
4370 node->psvi = cctxt->unknownItem;
4376 xsltCompilerNodePush(cctxt,
node);
4381 cctxt->inode->inScopeNs =
4382 xsltCompilerBuildInScopeNsList(cctxt,
node);
4388 IS_XSLT_ELEM_FAST(
child) &&
4391 cctxt->inode->curChildType = XSLT_FUNC_FALLBACK;
4392 xsltParseAnyXSLTElem(cctxt,
child);
4397 xsltCompilerNodePop(cctxt,
node);
4412 xsltParseSequenceConstructor(xsltCompilerCtxtPtr cctxt,
xmlNodePtr cur)
4417 if (cctxt ==
NULL) {
4419 "xsltParseSequenceConstructor: Bad arguments\n");
4420 cctxt->style->errors++;
4426 if (cctxt->inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4427 cctxt->inode->extContentHandled = 1;
4459 if (deleteNode !=
NULL) {
4460 #ifdef WITH_XSLT_DEBUG_BLANKS 4462 "xsltParseSequenceConstructor: removing xsl:text element\n");
4470 if (
cur->psvi == xsltXSLTTextMarker) {
4485 tmp =
cur->children;
4499 xmlAddPrevSibling(
cur, tmp);
4503 "Element 'xsl:text': Invalid type " 4504 "of node found in content.\n");
4505 cctxt->style->errors++;
4508 if (
cur->properties) {
4520 BAD_CAST "disable-output-escaping"))
4536 }
else if ((
attr->children ==
NULL) ||
4537 (
attr->children->content ==
NULL) ||
4543 "Attribute 'disable-output-escaping': " 4544 "Invalid value. Expected is " 4545 "'yes' or 'no'.\n");
4546 cctxt->style->errors++;
4553 }
else if (IS_XSLT_ELEM_FAST(
cur)) {
4563 type = xsltGetXSLTElementTypeByNode(cctxt,
cur);
4575 case XSLT_FUNC_FALLBACK:
4578 case XSLT_FUNC_MESSAGE:
4587 cctxt->inode->curChildType =
type;
4588 xsltParseAnyXSLTElem(cctxt,
cur);
4591 xsltParseUnknownXSLTElem(cctxt,
cur);
4600 xsltCompilerNodePush(cctxt,
cur);
4605 cctxt->inode->inScopeNs =
4606 xsltCompilerBuildInScopeNsList(cctxt,
cur);
4634 if (
cur->properties)
4635 cctxt->inode->extElemNs =
4636 xsltParseExtElemPrefixes(cctxt,
4637 cur, cctxt->inode->extElemNs,
4638 XSLT_ELEMENT_CATEGORY_LRE);
4643 (cctxt->inode->extElemNs !=
NULL) &&
4651 cctxt->inode->category = XSLT_ELEMENT_CATEGORY_EXTENSION;
4652 cctxt->inode->extContentHandled = 0;
4659 "Internal error in xsltParseSequenceConstructor(): " 4660 "Occupied PSVI field.\n");
4661 cctxt->style->errors++;
4665 cur->psvi = (
void *)
4703 if ((
cur->children !=
NULL) &&
4704 (cctxt->inode->extContentHandled == 0))
4710 xsltParseSequenceConstructor(cctxt,
cur->children);
4723 cctxt->inode->category = XSLT_ELEMENT_CATEGORY_LRE;
4724 if (
cur->properties !=
NULL) {
4729 cctxt->inode->exclResultNs =
4730 xsltParseExclResultPrefixes(cctxt,
cur,
4731 cctxt->inode->exclResultNs,
4732 XSLT_ELEMENT_CATEGORY_LRE);
4736 xsltParseAttrXSLTVersion(cctxt,
cur,
4737 XSLT_ELEMENT_CATEGORY_LRE);
4748 if ((
attr->psvi != xsltXSLTAttrMarker) &&
4749 IS_XSLT_ATTR_FAST(
attr))
4756 "Unknown XSLT attribute '%s'.\n",
4758 cctxt->style->errors++;
4763 attr->psvi = (
void *) xsltXSLTAttrMarker;
4772 if (cctxt->inode->nsChanged)
4773 xsltLREInfoCreate(cctxt,
cur, 1);
4774 cur->psvi = cctxt->inode->litResElemInfo;
4778 if (cctxt->hasNsAliases)
4779 xsltLREBuildEffectiveNs(cctxt,
cur);
4783 if (
cur->properties) {
4796 xsltParseSequenceConstructor(cctxt,
cur->children);
4802 xsltCompilerNodePop(cctxt,
cur);
4807 if (deleteNode !=
NULL) {
4808 #ifdef WITH_XSLT_DEBUG_BLANKS 4810 "xsltParseSequenceConstructor: removing xsl:text element\n");
4841 if (XSLT_CCTXT(
style)->
inode->category == XSLT_ELEMENT_CATEGORY_EXTENSION) {
4842 XSLT_CCTXT(
style)->inode->extContentHandled = 1;
4854 IS_XSLT_ELEM_FAST(
child) &&
4858 xsltParseAnyXSLTElem(XSLT_CCTXT(
style),
child);
4866 xsltParseSequenceConstructor(XSLT_CCTXT(
style),
child);
4896 if (
delete !=
NULL) {
4897 #ifdef WITH_XSLT_DEBUG_BLANKS 4899 "xsltParseTemplateContent: removing text\n");
4922 (
const xmlChar *)
"disable-output-escaping",
4925 #ifdef WITH_XSLT_DEBUG_PARSING 4927 "Disable escaping: %s\n",
text->content);
4934 "xsl:text: disable-output-escaping allows only yes or no\n");
4949 "xsltParseTemplateContent: xslt:text content problem\n");
4964 if ((
style->internalized) &&
4976 if (tmp !=
text->content) {
5010 style->defaultAlias);
5012 if (
cur->properties !=
NULL) {
5050 if (
delete !=
NULL) {
5051 #ifdef WITH_XSLT_DEBUG_PARSING 5053 "xsltParseTemplateContent: removing text\n");
5078 "xsltParseTemplateContent: ignoring misplaced param element\n");
5131 #ifdef WITH_XSLT_DEBUG_PARSING 5133 "xsltParseStylesheetKey: name %s\n",
name);
5137 "xsl:key : error missing name\n");
5145 "xsl:key : error missing match\n");
5153 "xsl:key : error missing use\n");
5171 if (nameURI !=
NULL)
5179 #ifdef XSLT_REFACTORED 5194 xsltParseXSLTTemplate(xsltCompilerCtxtPtr cctxt,
xmlNodePtr templNode) {
5199 if ((cctxt ==
NULL) || (templNode ==
NULL) ||
5210 xsltCompilerNodePush(cctxt, templNode);
5212 cctxt->inode->inScopeNs =
5213 xsltCompilerBuildInScopeNsList(cctxt, templNode);
5215 templ->
next = cctxt->style->templates;
5216 cctxt->style->templates = templ;
5217 templ->
style = cctxt->style;
5234 cctxt->style->errors++;
5240 if (xmlValidateNCName(templ->
mode, 0)) {
5242 "xsl:template: Attribute 'mode': The local part '%s' " 5243 "of the value is not a valid NCName.\n", templ->
name);
5244 cctxt->style->errors++;
5247 if (modeURI !=
NULL)
5249 #ifdef WITH_XSLT_DEBUG_PARSING 5251 "xsltParseXSLTTemplate: mode %s\n", templ->
mode);
5259 templ->
match = prop;
5285 cctxt->style->errors++;
5291 if (xmlValidateNCName(templ->
name, 0)) {
5293 "xsl:template: Attribute 'name': The local part '%s' of " 5294 "the value is not a valid NCName.\n", templ->
name);
5295 cctxt->style->errors++;
5298 if (nameURI !=
NULL)
5300 curTempl = templ->
next;
5301 while (curTempl !=
NULL) {
5308 "xsl:template: error duplicate name '%s'\n", templ->
name);
5309 cctxt->style->errors++;
5312 curTempl = curTempl->
next;