@@ -212,21 +212,10 @@ function findAncestorNs(doc, docSubsetXpath, namespaceResolver) {
212212
213213 // Remove namespaces which are already declared in the subset with the same prefix
214214 var returningNs = [ ] ;
215- var subsetAttributes = docSubset [ 0 ] . attributes ;
216- for ( var j = 0 ; j < ancestorNsWithoutDuplicate . length ; j ++ ) {
217- var isUnique = true ;
218- for ( var k = 0 ; k < subsetAttributes . length ; k ++ ) {
219- var nodeName = subsetAttributes [ k ] . nodeName ;
220- if ( nodeName . search ( / ^ x m l n s : / ) === - 1 ) continue ;
221- var prefix = nodeName . replace ( / ^ x m l n s : / , "" ) ;
222- if ( ancestorNsWithoutDuplicate [ j ] . prefix === prefix ) {
223- isUnique = false ;
224- break ;
225- }
226- }
227-
228- if ( isUnique ) {
229- returningNs . push ( ancestorNsWithoutDuplicate [ j ] ) ;
215+ const subsetNsPrefix = findNSPrefix ( docSubset [ 0 ] ) ;
216+ for ( const ancestorNs of ancestorNsWithoutDuplicate ) {
217+ if ( ancestorNs . prefix !== subsetNsPrefix ) {
218+ returningNs . push ( ancestorNs ) ;
230219 }
231220 }
232221
@@ -247,9 +236,9 @@ function collectAncestorNamespaces(node, nsArray) {
247236 if ( parent . attributes && parent . attributes . length > 0 ) {
248237 for ( var i = 0 ; i < parent . attributes . length ; i ++ ) {
249238 var attr = parent . attributes [ i ] ;
250- if ( attr && attr . nodeName && attr . nodeName . search ( / ^ x m l n s : / ) !== - 1 ) {
239+ if ( attr && attr . nodeName && attr . nodeName . search ( / ^ x m l n s : ? / ) !== - 1 ) {
251240 nsArray . push ( {
252- prefix : attr . nodeName . replace ( / ^ x m l n s : / , "" ) ,
241+ prefix : attr . nodeName . replace ( / ^ x m l n s : ? / , "" ) ,
253242 namespaceURI : attr . nodeValue ,
254243 } ) ;
255244 }
@@ -259,6 +248,17 @@ function collectAncestorNamespaces(node, nsArray) {
259248 return collectAncestorNamespaces ( parent , nsArray ) ;
260249}
261250
251+ function findNSPrefix ( subset ) {
252+ const subsetAttributes = subset . attributes ;
253+ for ( let k = 0 ; k < subsetAttributes . length ; k ++ ) {
254+ const nodeName = subsetAttributes [ k ] . nodeName ;
255+ if ( nodeName . search ( / ^ x m l n s : ? / ) !== - 1 ) {
256+ return nodeName . replace ( / ^ x m l n s : ? / , "" ) ;
257+ }
258+ }
259+ return subset . prefix || "" ;
260+ }
261+
262262/**
263263 * Xml signature implementation
264264 *
0 commit comments