Skip to content

Commit 3c9bec4

Browse files
committedNov 12, 2013
Use a priority queue when matching templates at the same import precedence
1 parent a702ece commit 3c9bec4

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed
 

‎README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ TODO
1212

1313
There are several tasks remaining to reach full compliance. Until these tasks are complete the API is subject to change.
1414

15-
* [ ] Distinguish between nodesets and RVTs (needed to pass 11.2-3)
16-
* [ ] Correctly resolve "/.." to the empty nodeset (needed to pass 11.2-6)
17-
* [ ] Fully implement xsl:include (no tests in initial suite)
18-
* [ ] Fully implement xsl:with-param (no tests in initial suite)
19-
* [ ] Ensure that errors are properly progogated in Go fashion.
15+
* Fully implement xsl:include (see tests in libxslt general suite)
16+
* Fully implement xsl:with-param (no tests in initial suite)
17+
* Ensure that errors are properly progogated in Go fashion.
2018

‎xslt/stylesheet.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -439,34 +439,48 @@ func (style *Stylesheet) LookupTemplate(node xml.Node, mode string, context *Exe
439439
for i := style.IdKeyMatches.Front(); i != nil; i = i.Next() {
440440
c := i.Value.(*CompiledMatch)
441441
if c.EvalMatch(node, mode, context) {
442-
return c.Template
442+
insertByPriority(found, c)
443+
break
443444
}
444445
}
445446
for i := style.NodeMatches.Front(); i != nil; i = i.Next() {
446447
c := i.Value.(*CompiledMatch)
447448
if c.EvalMatch(node, mode, context) {
448-
return c.Template
449+
insertByPriority(found, c)
450+
break
449451
}
450452
}
451453
for i := style.TextMatches.Front(); i != nil; i = i.Next() {
452454
c := i.Value.(*CompiledMatch)
453455
if c.EvalMatch(node, mode, context) {
454-
return c.Template
456+
insertByPriority(found, c)
457+
break
455458
}
456459
}
457460
for i := style.PIMatches.Front(); i != nil; i = i.Next() {
458461
c := i.Value.(*CompiledMatch)
459462
if c.EvalMatch(node, mode, context) {
460-
return c.Template
463+
insertByPriority(found, c)
464+
break
461465
}
462466
}
463467
for i := style.CommentMatches.Front(); i != nil; i = i.Next() {
464468
c := i.Value.(*CompiledMatch)
465469
if c.EvalMatch(node, mode, context) {
466-
return c.Template
470+
insertByPriority(found, c)
471+
break
467472
}
468473
}
469474

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,
470484
//consult the imported stylesheets
471485
for i := style.Imports.Front(); i != nil; i = i.Next() {
472486
s := i.Value.(*Stylesheet)
@@ -475,10 +489,6 @@ func (style *Stylesheet) LookupTemplate(node xml.Node, mode string, context *Exe
475489
return t
476490
}
477491
}
478-
f := found.Front()
479-
if f != nil {
480-
template = f.Value.(*CompiledMatch).Template
481-
}
482492
return
483493
}
484494

‎xslt/stylesheet_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestXsltGeneral(t *testing.T) {
115115
//runGeneralXslTest(t, "bug-5-") //seems to be an issue with for-each select=$ACTIONgrid
116116
runGeneralXslTest(t, "bug-6-")
117117
runGeneralXslTest(t, "bug-7-")
118-
//runGeneralXslTest(t, "bug-8-")
118+
//runGeneralXslTest(t, "bug-8-") //issue resolving imported template?
119119
runGeneralXslTest(t, "bug-9-")
120120
runGeneralXslTest(t, "bug-10-")
121121
runGeneralXslTest(t, "bug-11-")
@@ -150,7 +150,7 @@ func TestXsltGeneral(t *testing.T) {
150150
//runGeneralXslTest(t, "bug-100") // libxslt:test extension element
151151
runGeneralXslTest(t, "bug-101") // xsl:element with default namespace
152152
//runGeneralXslTest(t, "bug-102") // imported xsl:attribute-set
153-
//runGeneralXslTest(t, "bug-103") //copy-of needs to explcitly set empty namespace when needed
153+
//runGeneralXslTest(t, "bug-103") //copy-of needs to explicitly set empty namespace when needed
154154
//runGeneralXslTest(t, "bug-104") //copy-of should preserve attr prefix if plausible
155155
runGeneralXslTest(t, "bug-105")
156156
runGeneralXslTest(t, "bug-106") //copy-of

0 commit comments

Comments
 (0)