@@ -439,34 +439,48 @@ func (style *Stylesheet) LookupTemplate(node xml.Node, mode string, context *Exe
439
439
for i := style .IdKeyMatches .Front (); i != nil ; i = i .Next () {
440
440
c := i .Value .(* CompiledMatch )
441
441
if c .EvalMatch (node , mode , context ) {
442
- return c .Template
442
+ insertByPriority (found , c )
443
+ break
443
444
}
444
445
}
445
446
for i := style .NodeMatches .Front (); i != nil ; i = i .Next () {
446
447
c := i .Value .(* CompiledMatch )
447
448
if c .EvalMatch (node , mode , context ) {
448
- return c .Template
449
+ insertByPriority (found , c )
450
+ break
449
451
}
450
452
}
451
453
for i := style .TextMatches .Front (); i != nil ; i = i .Next () {
452
454
c := i .Value .(* CompiledMatch )
453
455
if c .EvalMatch (node , mode , context ) {
454
- return c .Template
456
+ insertByPriority (found , c )
457
+ break
455
458
}
456
459
}
457
460
for i := style .PIMatches .Front (); i != nil ; i = i .Next () {
458
461
c := i .Value .(* CompiledMatch )
459
462
if c .EvalMatch (node , mode , context ) {
460
- return c .Template
463
+ insertByPriority (found , c )
464
+ break
461
465
}
462
466
}
463
467
for i := style .CommentMatches .Front (); i != nil ; i = i .Next () {
464
468
c := i .Value .(* CompiledMatch )
465
469
if c .EvalMatch (node , mode , context ) {
466
- return c .Template
470
+ insertByPriority (found , c )
471
+ break
467
472
}
468
473
}
469
474
475
+ // if there's a match at this import precedence, return
476
+ // the one with the highest priority
477
+ f := found .Front ()
478
+ if f != nil {
479
+ template = f .Value .(* CompiledMatch ).Template
480
+ return
481
+ }
482
+
483
+ // no match at this import precedence,
470
484
//consult the imported stylesheets
471
485
for i := style .Imports .Front (); i != nil ; i = i .Next () {
472
486
s := i .Value .(* Stylesheet )
@@ -475,10 +489,6 @@ func (style *Stylesheet) LookupTemplate(node xml.Node, mode string, context *Exe
475
489
return t
476
490
}
477
491
}
478
- f := found .Front ()
479
- if f != nil {
480
- template = f .Value .(* CompiledMatch ).Template
481
- }
482
492
return
483
493
}
484
494
0 commit comments