ReactOS 0.4.16-dev-2208-g6350669
namespaces.h File Reference
#include <libxml/tree.h>
#include "xsltexports.h"
Include dependency graph for namespaces.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UNDEFINED_DEFAULT_NS   (const xmlChar *) -1L
 

Functions

XSLTPUBFUN void XSLTCALL xsltNamespaceAlias (xsltStylesheetPtr style, xmlNodePtr node)
 
XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetNamespace (xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, xmlNodePtr out)
 
XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetPlainNamespace (xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, xmlNodePtr out)
 
XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetSpecialNamespace (xsltTransformContextPtr ctxt, xmlNodePtr cur, const xmlChar *URI, const xmlChar *prefix, xmlNodePtr out)
 
XSLTPUBFUN xmlNsPtr XSLTCALL xsltCopyNamespace (xsltTransformContextPtr ctxt, xmlNodePtr elem, xmlNsPtr ns)
 
XSLTPUBFUN xmlNsPtr XSLTCALL xsltCopyNamespaceList (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNsPtr cur)
 
XSLTPUBFUN void XSLTCALL xsltFreeNamespaceAliasHashes (xsltStylesheetPtr style)
 

Macro Definition Documentation

◆ UNDEFINED_DEFAULT_NS

#define UNDEFINED_DEFAULT_NS   (const xmlChar *) -1L

UNDEFINED_DEFAULT_NS:

Special value for undefined namespace, internal

Definition at line 30 of file namespaces.h.

Function Documentation

◆ xsltCopyNamespace()

XSLTPUBFUN xmlNsPtr XSLTCALL xsltCopyNamespace ( xsltTransformContextPtr ctxt  ATTRIBUTE_UNUSED,
xmlNodePtr  elem,
xmlNsPtr  ns 
)

xsltCopyNamespace: @ctxt: a transformation context @elem: the target element node @ns: the namespace node

Copies a namespace node (declaration). If @elem is not NULL, then the new namespace will be declared on @elem.

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

Definition at line 809 of file namespaces.c.

811{
812 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL))
813 return(NULL);
814 /*
815 * One can add namespaces only on element nodes
816 */
817 if ((elem != NULL) && (elem->type != XML_ELEMENT_NODE))
818 return(xmlNewNs(NULL, ns->href, ns->prefix));
819 else
820 return(xmlNewNs(elem, ns->href, ns->prefix));
821}
#define NULL
Definition: types.h:112
static size_t elem
Definition: string.c:71
Definition: mxnamespace.c:38
BSTR prefix
Definition: mxnamespace.c:39

◆ xsltCopyNamespaceList()

XSLTPUBFUN xmlNsPtr XSLTCALL xsltCopyNamespaceList ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node,
xmlNsPtr  cur 
)

xsltCopyNamespaceList: @ctxt: a transformation context @node: the target node @cur: the first namespace

Do a copy of an namespace list. If @node is non-NULL the new namespaces are added automatically. This handles namespaces aliases. This function is intended only for internal use at transformation-time for copying ns-declarations of Literal Result Elements.

Called by: xsltCopyTreeInternal() (transform.c) xsltShallowCopyElem() (transform.c)

REVISIT: This function won't be used in the refactored code.

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

Definition at line 717 of file namespaces.c.

718 {
719 xmlNsPtr ret = NULL, tmp;
720 xmlNsPtr p = NULL,q;
721
722 if (cur == NULL)
723 return(NULL);
724 if (cur->type != XML_NAMESPACE_DECL)
725 return(NULL);
726
727 /*
728 * One can add namespaces only on element nodes
729 */
730 if ((node != NULL) && (node->type != XML_ELEMENT_NODE))
731 node = NULL;
732
733 while (cur != NULL) {
734 if (cur->type != XML_NAMESPACE_DECL)
735 break;
736
737 /*
738 * Avoid duplicating namespace declarations in the tree if
739 * a matching declaration is in scope.
740 */
741 if (node != NULL) {
742 if ((node->ns != NULL) &&
743 (xmlStrEqual(node->ns->prefix, cur->prefix)) &&
744 (xmlStrEqual(node->ns->href, cur->href))) {
745 cur = cur->next;
746 continue;
747 }
748 tmp = xmlSearchNs(node->doc, node, cur->prefix);
749 if ((tmp != NULL) && (xmlStrEqual(tmp->href, cur->href))) {
750 cur = cur->next;
751 continue;
752 }
753 }
754#ifdef XSLT_REFACTORED
755 /*
756 * Namespace exclusion and ns-aliasing is performed at
757 * compilation-time in the refactored code.
758 */
759 q = xmlNewNs(node, cur->href, cur->prefix);
760 if (p == NULL) {
761 ret = p = q;
762 } else {
763 p->next = q;
764 p = q;
765 }
766#else
767 /*
768 * TODO: Remove this if the refactored code gets enabled.
769 */
770 if (!xmlStrEqual(cur->href, XSLT_NAMESPACE)) {
771 const xmlChar *URI;
772 /* TODO apply cascading */
773 URI = (const xmlChar *) xmlHashLookup(ctxt->style->nsAliases,
774 cur->href);
775 if (URI == UNDEFINED_DEFAULT_NS) {
776 cur = cur->next;
777 continue;
778 }
779 if (URI != NULL) {
780 q = xmlNewNs(node, URI, cur->prefix);
781 } else {
782 q = xmlNewNs(node, cur->href, cur->prefix);
783 }
784 if (p == NULL) {
785 ret = p = q;
786 } else {
787 p->next = q;
788 p = q;
789 }
790 }
791#endif
792 cur = cur->next;
793 }
794 return(ret);
795}
return ret
Definition: mutex.c:146
FxCollectionEntry * cur
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define UNDEFINED_DEFAULT_NS
Definition: namespaces.h:30
void * xmlHashLookup(xmlHashTablePtr hash, const xmlChar *key)
Definition: hash.c:739
xmlHashTablePtr nsAliases
xsltStylesheetPtr style
Definition: dlist.c:348
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:162
unsigned char xmlChar
Definition: xmlstring.h:28
#define XSLT_NAMESPACE
Definition: xslt.h:46

Referenced by xsltCopyTree(), and xsltShallowCopyElem().

◆ xsltFreeNamespaceAliasHashes()

XSLTPUBFUN void XSLTCALL xsltFreeNamespaceAliasHashes ( xsltStylesheetPtr  style)

xsltFreeNamespaceAliasHashes: @style: an XSLT stylesheet

Free up the memory used by namespaces aliases

Definition at line 831 of file namespaces.c.

831 {
832 if (style->nsAliases != NULL)
833 xmlHashFree((xmlHashTablePtr) style->nsAliases, NULL);
834 style->nsAliases = NULL;
835}
Arabic default style
Definition: afstyles.h:94
void xmlHashFree(xmlHashTablePtr hash, xmlHashDeallocator dealloc)
Definition: hash.c:229

Referenced by xsltFreeStylesheet().

◆ xsltGetNamespace()

XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetNamespace ( xsltTransformContextPtr  ctxt,
xmlNodePtr  cur,
xmlNsPtr  ns,
xmlNodePtr  out 
)

xsltGetNamespace: @ctxt: a transformation context @cur: the input node @ns: the namespace @out: the output node (or its parent)

Find a matching (prefix and ns-name) ns-declaration for the requested @ns->prefix and @ns->href in the result tree. If none is found then a new ns-declaration will be added to @resultElem. If, in this case, the given prefix is already in use, then a ns-declaration with a modified ns-prefix be we created.

Called by:

Returns a namespace declaration or NULL in case of namespace fixup failures or API or internal errors.

Definition at line 616 of file namespaces.c.

618{
619
620 if (ns == NULL)
621 return(NULL);
622
623#ifdef XSLT_REFACTORED
624 /*
625 * Namespace exclusion and ns-aliasing is performed at
626 * compilation-time in the refactored code.
627 * Additionally, aliasing is not intended for non Literal
628 * Result Elements.
629 */
630 return(xsltGetSpecialNamespace(ctxt, cur, ns->href, ns->prefix, out));
631#else
632 {
634 const xmlChar *URI = NULL; /* the replacement URI */
635
636 if ((ctxt == NULL) || (cur == NULL) || (out == NULL))
637 return(NULL);
638
639 style = ctxt->style;
640 while (style != NULL) {
641 if (style->nsAliases != NULL)
642 URI = (const xmlChar *)
643 xmlHashLookup(style->nsAliases, ns->href);
644 if (URI != NULL)
645 break;
646
648 }
649
650
651 if (URI == UNDEFINED_DEFAULT_NS) {
652 return(xsltGetSpecialNamespace(ctxt, cur, NULL, NULL, out));
653#if 0
654 /*
655 * TODO: Removed, since wrong. If there was no default
656 * namespace in the stylesheet then this must resolve to
657 * the NULL namespace.
658 */
659 xmlNsPtr dflt;
660 dflt = xmlSearchNs(cur->doc, cur, NULL);
661 if (dflt != NULL)
662 URI = dflt->href;
663 else
664 return NULL;
665#endif
666 } else if (URI == NULL)
667 URI = ns->href;
668
669 return(xsltGetSpecialNamespace(ctxt, cur, URI, ns->prefix, out));
670 }
671#endif
672}
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:297
xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr invocNode, const xmlChar *nsName, const xmlChar *nsPrefix, xmlNodePtr target)
Definition: namespaces.c:319
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by xsltApplySequenceConstructor(), xsltAttrListTemplateProcess(), xsltAttrTemplateProcess(), xsltGetPlainNamespace(), and xsltShallowCopyElem().

◆ xsltGetPlainNamespace()

XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetPlainNamespace ( xsltTransformContextPtr  ctxt,
xmlNodePtr  cur,
xmlNsPtr  ns,
xmlNodePtr  out 
)

xsltGetPlainNamespace: @ctxt: a transformation context @cur: the input node @ns: the namespace @out: the result element

Obsolete. Not called by any Libxslt/Libexslt function. Exaclty the same as xsltGetNamespace().

Returns a namespace declaration or NULL in case of namespace fixup failures or API or internal errors.

Definition at line 689 of file namespaces.c.

691{
692 return(xsltGetNamespace(ctxt, cur, ns, out));
693}
xmlNsPtr xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, xmlNodePtr out)
Definition: namespaces.c:616

◆ xsltGetSpecialNamespace()

XSLTPUBFUN xmlNsPtr XSLTCALL xsltGetSpecialNamespace ( xsltTransformContextPtr  ctxt,
xmlNodePtr  invocNode,
const xmlChar nsName,
const xmlChar nsPrefix,
xmlNodePtr  target 
)

xsltGetSpecialNamespace: @ctxt: the transformation context @invocNode: the invoking node; e.g. a literal result element/attr; only used for error reports @nsName: the namespace name (or NULL) @nsPrefix: the suggested namespace prefix (or NULL) @target: the result element on which to anchor a namespace

Find a matching (prefix and ns-name) ns-declaration for the requested @nsName and @nsPrefix in the result tree. If none is found then a new ns-declaration will be added to @resultElem. If, in this case, the given prefix is already in use, then a ns-declaration with a modified ns-prefix be we created. Note that this function's priority is to preserve ns-prefixes; it will only change a prefix if there's a namespace clash. If both @nsName and @nsPrefix are NULL, then this will try to "undeclare" a default namespace by declaring an xmlns="".

Returns a namespace declaration or NULL.

Definition at line 319 of file namespaces.c.

322{
323 xmlNsPtr ns;
324 int prefixOccupied = 0;
325
326 if ((ctxt == NULL) || (target == NULL) ||
327 (target->type != XML_ELEMENT_NODE))
328 return(NULL);
329
330 /*
331 * NOTE: Namespace exclusion and ns-aliasing is performed at
332 * compilation-time in the refactored code; so this need not be done
333 * here (it was in the old code).
334 * NOTE: @invocNode was named @cur in the old code and was documented to
335 * be an input node; since it was only used to anchor an error report
336 * somewhere, we can safely change this to @invocNode, which now
337 * will be the XSLT instruction (also a literal result element/attribute),
338 * which was responsible for this call.
339 */
340 /*
341 * OPTIMIZE TODO: This all could be optimized by keeping track of
342 * the ns-decls currently in-scope via a specialized context.
343 */
344 if ((nsPrefix == NULL) && ((nsName == NULL) || (nsName[0] == 0))) {
345 /*
346 * NOTE: the "undeclaration" of the default namespace was
347 * part of the logic of the old xsltGetSpecialNamespace() code,
348 * so we'll keep that mechanism.
349 * Related to the old code: bug #302020:
350 */
351 /*
352 * OPTIMIZE TODO: This all could be optimized by keeping track of
353 * the ns-decls currently in-scope via a specialized context.
354 */
355 /*
356 * Search on the result element itself.
357 */
358 if (target->nsDef != NULL) {
359 ns = target->nsDef;
360 do {
361 if (ns->prefix == NULL) {
362 if ((ns->href != NULL) && (ns->href[0] != 0)) {
363 /*
364 * Raise a namespace normalization error.
365 */
366 xsltTransformError(ctxt, NULL, invocNode,
367 "Namespace normalization error: Cannot undeclare "
368 "the default namespace, since the default namespace "
369 "'%s' is already declared on the result element "
370 "'%s'.\n", ns->href, target->name);
371 return(NULL);
372 } else {
373 /*
374 * The default namespace was undeclared on the
375 * result element.
376 */
377 return(NULL);
378 }
379 break;
380 }
381 ns = ns->next;
382 } while (ns != NULL);
383 }
384 if ((target->parent != NULL) &&
385 (target->parent->type == XML_ELEMENT_NODE))
386 {
387 /*
388 * The parent element is in no namespace, so assume
389 * that there is no default namespace in scope.
390 */
391 if (target->parent->ns == NULL)
392 return(NULL);
393
394 ns = xmlSearchNs(target->doc, target->parent,
395 NULL);
396 /*
397 * Fine if there's no default ns is scope, or if the
398 * default ns was undeclared.
399 */
400 if ((ns == NULL) || (ns->href == NULL) || (ns->href[0] == 0))
401 return(NULL);
402
403 /*
404 * Undeclare the default namespace.
405 */
406 xmlNewNs(target, BAD_CAST "", NULL);
407 /* TODO: Check result */
408 return(NULL);
409 }
410 return(NULL);
411 }
412 /*
413 * Handle the XML namespace.
414 * QUESTION: Is this faster than using xmlStrEqual() anyway?
415 */
416 if ((nsPrefix != NULL) &&
417 (nsPrefix[0] == 'x') && (nsPrefix[1] == 'm') &&
418 (nsPrefix[2] == 'l') && (nsPrefix[3] == 0))
419 {
420 return(xmlSearchNs(target->doc, target, nsPrefix));
421 }
422 /*
423 * First: search on the result element itself.
424 */
425 if (target->nsDef != NULL) {
426 ns = target->nsDef;
427 do {
428 if ((ns->prefix == NULL) == (nsPrefix == NULL)) {
429 if (ns->prefix == nsPrefix) {
430 if (xmlStrEqual(ns->href, nsName))
431 return(ns);
432 prefixOccupied = 1;
433 break;
434 } else if (xmlStrEqual(ns->prefix, nsPrefix)) {
435 if (xmlStrEqual(ns->href, nsName))
436 return(ns);
437 prefixOccupied = 1;
438 break;
439 }
440 }
441 ns = ns->next;
442 } while (ns != NULL);
443 }
444 if (prefixOccupied) {
445 /*
446 * If the ns-prefix is occupied by an other ns-decl on the
447 * result element, then this means:
448 * 1) The desired prefix is shadowed
449 * 2) There's no way around changing the prefix
450 *
451 * Try a desperate search for an in-scope ns-decl
452 * with a matching ns-name before we use the last option,
453 * which is to recreate the ns-decl with a modified prefix.
454 */
455 ns = xmlSearchNsByHref(target->doc, target, nsName);
456 if (ns != NULL)
457 return(ns);
458
459 /*
460 * Fallback to changing the prefix.
461 */
462 } else if ((target->parent != NULL) &&
463 (target->parent->type == XML_ELEMENT_NODE))
464 {
465 /*
466 * Try to find a matching ns-decl in the ancestor-axis.
467 *
468 * Check the common case: The parent element of the current
469 * result element is in the same namespace (with an equal ns-prefix).
470 */
471 if ((target->parent->ns != NULL) &&
472 ((target->parent->ns->prefix != NULL) == (nsPrefix != NULL)))
473 {
474 ns = target->parent->ns;
475
476 if (nsPrefix == NULL) {
477 if (xmlStrEqual(ns->href, nsName))
478 return(ns);
479 } else if (xmlStrEqual(ns->prefix, nsPrefix) &&
480 xmlStrEqual(ns->href, nsName))
481 {
482 return(ns);
483 }
484 }
485 /*
486 * Lookup the remaining in-scope namespaces.
487 */
488 ns = xmlSearchNs(target->doc, target->parent, nsPrefix);
489 if (ns != NULL) {
490 if (xmlStrEqual(ns->href, nsName))
491 return(ns);
492 /*
493 * Now check for a nasty case: We need to ensure that the new
494 * ns-decl won't shadow a prefix in-use by an existing attribute.
495 * <foo xmlns:a="urn:test:a">
496 * <bar a:a="val-a">
497 * <xsl:attribute xmlns:a="urn:test:b" name="a:b">
498 * val-b</xsl:attribute>
499 * </bar>
500 * </foo>
501 */
502 if (target->properties) {
503 xmlAttrPtr attr = target->properties;
504 do {
505 if ((attr->ns) &&
506 xmlStrEqual(attr->ns->prefix, nsPrefix))
507 {
508 /*
509 * Bad, this prefix is already in use.
510 * Since we'll change the prefix anyway, try
511 * a search for a matching ns-decl based on the
512 * namespace name.
513 */
514 ns = xmlSearchNsByHref(target->doc, target, nsName);
515 if (ns != NULL)
516 return(ns);
517 goto declare_new_prefix;
518 }
519 attr = attr->next;
520 } while (attr != NULL);
521 }
522 } else {
523 /*
524 * Either no matching ns-prefix was found or the namespace is
525 * shadowed.
526 * Create a new ns-decl on the current result element.
527 *
528 * Hmm, we could also try to reuse an in-scope
529 * namespace with a matching ns-name but a different
530 * ns-prefix.
531 * What has higher priority?
532 * 1) If keeping the prefix: create a new ns-decl.
533 * 2) If reusal: first lookup ns-names; then fallback
534 * to creation of a new ns-decl.
535 * REVISIT: this currently uses case 1) although
536 * the old way was use xmlSearchNsByHref() and to let change
537 * the prefix.
538 */
539#if 0
540 ns = xmlSearchNsByHref(target->doc, target, nsName);
541 if (ns != NULL)
542 return(ns);
543#endif
544 }
545 /*
546 * Create the ns-decl on the current result element.
547 */
548 ns = xmlNewNs(target, nsName, nsPrefix);
549 /* TODO: check errors */
550 return(ns);
551 } else {
552 /*
553 * This is either the root of the tree or something weird is going on.
554 */
555 ns = xmlNewNs(target, nsName, nsPrefix);
556 /* TODO: Check result */
557 return(ns);
558 }
559
560declare_new_prefix:
561 /*
562 * Fallback: we need to generate a new prefix and declare the namespace
563 * on the result element.
564 */
565 {
566 xmlChar pref[30];
567 int counter = 1;
568
569 if (nsPrefix == NULL) {
570 nsPrefix = BAD_CAST "ns";
571 }
572
573 do {
574 snprintf((char *) pref, 30, "%s_%d", nsPrefix, counter++);
575 ns = xmlSearchNs(target->doc, target, BAD_CAST pref);
576 if (counter > 1000) {
577 xsltTransformError(ctxt, NULL, invocNode,
578 "Internal error in xsltAcquireResultInScopeNs(): "
579 "Failed to compute a unique ns-prefix for the "
580 "generated element");
581 return(NULL);
582 }
583 } while (ns != NULL);
584 ns = xmlNewNs(target, nsName, BAD_CAST pref);
585 /* TODO: Check result */
586 return(ns);
587 }
588 return(NULL);
589}
Definition: cookie.c:202
Definition: tools.h:99
#define snprintf
Definition: wintirpc.h:48
#define BAD_CAST
Definition: xmlstring.h:35
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762

Referenced by xsltApplySequenceConstructor(), xsltAttribute(), xsltAttrListTemplateProcess(), xsltCopyAttrListNoOverwrite(), xsltCopyTree(), xsltElement(), xsltGetNamespace(), xsltShallowCopyAttr(), and xsltShallowCopyElem().

◆ xsltNamespaceAlias()

XSLTPUBFUN void XSLTCALL xsltNamespaceAlias ( xsltStylesheetPtr  style,
xmlNodePtr  node 
)

xsltNamespaceAlias: @style: the XSLT stylesheet @node: the xsl:namespace-alias node

Read the stylesheet-prefix and result-prefix attributes, register them as well as the corresponding namespace.

Definition at line 75 of file namespaces.c.

76{
77 xmlChar *resultPrefix = NULL;
78 xmlChar *stylePrefix = NULL;
79 xmlNsPtr literalNs = NULL;
80 xmlNsPtr targetNs = NULL;
81
82#ifdef XSLT_REFACTORED
83 xsltNsAliasPtr alias;
84
85 if ((style == NULL) || (node == NULL))
86 return;
87
88 /*
89 * SPEC XSLT 1.0:
90 * "If a namespace URI is declared to be an alias for multiple
91 * different namespace URIs, then the declaration with the highest
92 * import precedence is used. It is an error if there is more than
93 * one such declaration. An XSLT processor may signal the error;
94 * if it does not signal the error, it must recover by choosing,
95 * from amongst the declarations with the highest import precedence,
96 * the one that occurs last in the stylesheet."
97 *
98 * SPEC TODO: Check for the errors mentioned above.
99 */
100 /*
101 * NOTE that the XSLT 2.0 also *does* use the NULL namespace if
102 * "#default" is used and there's no default namespace is scope.
103 * I.e., this is *not* an error.
104 * Most XSLT 1.0 implementations work this way.
105 * The XSLT 1.0 spec has nothing to say on the subject.
106 */
107 /*
108 * Attribute "stylesheet-prefix".
109 */
110 stylePrefix = xmlGetNsProp(node, (const xmlChar *)"stylesheet-prefix", NULL);
111 if (stylePrefix == NULL) {
113 "The attribute 'stylesheet-prefix' is missing.\n");
114 return;
115 }
116 if (xmlStrEqual(stylePrefix, (const xmlChar *)"#default"))
117 literalNs = xmlSearchNs(node->doc, node, NULL);
118 else {
119 literalNs = xmlSearchNs(node->doc, node, stylePrefix);
120 if (literalNs == NULL) {
122 "Attribute 'stylesheet-prefix': There's no namespace "
123 "declaration in scope for the prefix '%s'.\n",
124 stylePrefix);
125 goto error;
126 }
127 }
128 /*
129 * Attribute "result-prefix".
130 */
131 resultPrefix = xmlGetNsProp(node, (const xmlChar *)"result-prefix", NULL);
132 if (resultPrefix == NULL) {
134 "The attribute 'result-prefix' is missing.\n");
135 goto error;
136 }
137 if (xmlStrEqual(resultPrefix, (const xmlChar *)"#default"))
138 targetNs = xmlSearchNs(node->doc, node, NULL);
139 else {
140 targetNs = xmlSearchNs(node->doc, node, resultPrefix);
141
142 if (targetNs == NULL) {
144 "Attribute 'result-prefix': There's no namespace "
145 "declaration in scope for the prefix '%s'.\n",
146 stylePrefix);
147 goto error;
148 }
149 }
150 /*
151 *
152 * Same alias for multiple different target namespace URIs:
153 * TODO: The one with the highest import precedence is used.
154 * Example:
155 * <xsl:namespace-alias stylesheet-prefix="foo"
156 * result-prefix="bar"/>
157 *
158 * <xsl:namespace-alias stylesheet-prefix="foo"
159 * result-prefix="zar"/>
160 *
161 * Same target namespace URI for multiple different aliases:
162 * All alias-definitions will be used.
163 * Example:
164 * <xsl:namespace-alias stylesheet-prefix="bar"
165 * result-prefix="foo"/>
166 *
167 * <xsl:namespace-alias stylesheet-prefix="zar"
168 * result-prefix="foo"/>
169 * Cases using #default:
170 * <xsl:namespace-alias stylesheet-prefix="#default"
171 * result-prefix="#default"/>
172 * TODO: Has this an effect at all?
173 *
174 * <xsl:namespace-alias stylesheet-prefix="foo"
175 * result-prefix="#default"/>
176 * From namespace to no namespace.
177 *
178 * <xsl:namespace-alias stylesheet-prefix="#default"
179 * result-prefix="foo"/>
180 * From no namespace to namespace.
181 */
182
183
184 /*
185 * Store the ns-node in the alias-object.
186 */
187 alias = xsltNewNsAlias(XSLT_CCTXT(style));
188 if (alias == NULL)
189 return;
190 alias->literalNs = literalNs;
191 alias->targetNs = targetNs;
192 XSLT_CCTXT(style)->hasNsAliases = 1;
193
194
195#else /* XSLT_REFACTORED */
196 const xmlChar *literalNsName;
197 const xmlChar *targetNsName;
198
199
200 if ((style == NULL) || (node == NULL))
201 return;
202
203 stylePrefix = xmlGetNsProp(node, (const xmlChar *)"stylesheet-prefix", NULL);
204 if (stylePrefix == NULL) {
206 "namespace-alias: stylesheet-prefix attribute missing\n");
207 return;
208 }
209 resultPrefix = xmlGetNsProp(node, (const xmlChar *)"result-prefix", NULL);
210 if (resultPrefix == NULL) {
212 "namespace-alias: result-prefix attribute missing\n");
213 goto error;
214 }
215
216 if (xmlStrEqual(stylePrefix, (const xmlChar *)"#default")) {
217 literalNs = xmlSearchNs(node->doc, node, NULL);
218 if (literalNs == NULL) {
219 literalNsName = NULL;
220 } else
221 literalNsName = literalNs->href; /* Yes - set for nsAlias table */
222 } else {
223 literalNs = xmlSearchNs(node->doc, node, stylePrefix);
224
225 if ((literalNs == NULL) || (literalNs->href == NULL)) {
227 "namespace-alias: prefix %s not bound to any namespace\n",
228 stylePrefix);
229 goto error;
230 } else
231 literalNsName = literalNs->href;
232 }
233
234 /*
235 * When "#default" is used for result, if a default namespace has not
236 * been explicitly declared the special value UNDEFINED_DEFAULT_NS is
237 * put into the nsAliases table
238 */
239 if (xmlStrEqual(resultPrefix, (const xmlChar *)"#default")) {
240 targetNs = xmlSearchNs(node->doc, node, NULL);
241 if (targetNs == NULL) {
242 targetNsName = UNDEFINED_DEFAULT_NS;
243 } else
244 targetNsName = targetNs->href;
245 } else {
246 targetNs = xmlSearchNs(node->doc, node, resultPrefix);
247
248 if ((targetNs == NULL) || (targetNs->href == NULL)) {
250 "namespace-alias: prefix %s not bound to any namespace\n",
251 resultPrefix);
252 goto error;
253 } else
254 targetNsName = targetNs->href;
255 }
256 /*
257 * Special case: if #default is used for
258 * the stylesheet-prefix (literal namespace) and there's no default
259 * namespace in scope, we'll use style->defaultAlias for this.
260 */
261 if (literalNsName == NULL) {
262 if (targetNs != NULL) {
263 /*
264 * BUG TODO: Is it not sufficient to have only 1 field for
265 * this, since subsequently alias declarations will
266 * overwrite this.
267 * Example:
268 * <xsl:namespace-alias result-prefix="foo"
269 * stylesheet-prefix="#default"/>
270 * <xsl:namespace-alias result-prefix="bar"
271 * stylesheet-prefix="#default"/>
272 * The mapping for "foo" won't be visible anymore.
273 */
274 style->defaultAlias = targetNs->href;
275 }
276 } else {
277 if (style->nsAliases == NULL)
278 style->nsAliases = xmlHashCreate(10);
279 if (style->nsAliases == NULL) {
281 "namespace-alias: cannot create hash table\n");
282 goto error;
283 }
285 literalNsName, (void *) targetNsName);
286 }
287#endif /* else of XSLT_REFACTORED */
288
289error:
290 if (stylePrefix != NULL)
291 xmlFree(stylePrefix);
292 if (resultPrefix != NULL)
293 xmlFree(resultPrefix);
294}
const WCHAR * alias
Definition: main.c:67
#define error(str)
Definition: mkdosfs.c:1605
xmlFreeFunc xmlFree
Definition: globals.c:184
int xmlHashAddEntry(xmlHashTablePtr hash, const xmlChar *key, void *payload)
Definition: hash.c:621
xmlHashTablePtr xmlHashCreate(int size)
Definition: hash.c:160

Referenced by xsltParseStylesheetTop().