Ignoring XML namespace prefix while selecting elements - XSLT

后端 未结 2 1001
生来不讨喜
生来不讨喜 2021-01-23 12:10

XML Version 1



        

        
2条回答
  •  失恋的感觉
    2021-01-23 12:49

    The College element is bound to the same namespace for both documents.

    Whether or not the XML documents use a namespace-prefix or if they have different prefix values is irrelevant. They are "seen" by the XML processor as the same type of element and are addressed the same way through XPath, since they are bound to the same namespace.

    The namespace-prefix used in an XPath statement does not have to match the namespace-prefix in the XML document (as it would be impossible to predict what namesapce-prefixes someone might choose to use). However, the namespace that it is bound to must match.

    Both of your XML documents are equivalent. Whether or not the elements have a namaspece-prefix, the elements are bound to the same namespaces.

    If you look at how they are declared and what they map to, in the first XML document:

    
    

    declares an element named College without a namespace-prefix that is bound to the namespace urn:abc:names:specification:col:schema:all:5:0 because of the declaration of the namespace without a namespace-prefix xmlns="urn:abc:names:specification:col:schema:all:5:0".

    In the second example:

    
    

    Declares an element named College using a namespace-prefix which is bound to the namespace urn:abc:names:specification:col:schema:all:5:0.

    The descendant elements of those College elements in both examples are bound to the same namespace as the College element that defined what the namespace for the ns1 namespace-prefix in the first example, or the null namespace-prefix in the second example document.

    Any XSLT and XPath addressing those elements should return the same results.

    Your template match in your XSLT should not work for either documents, as College is not a child of inboundData.

    You would either need to adjust it to:

    b:inboundData/b:Root/a:College/*
    

    or

    b:inboundData//a:College/*
    

提交回复
热议问题