summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/xml/transform/Stylesheet.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/xml/transform/Stylesheet.java')
-rw-r--r--libjava/classpath/gnu/xml/transform/Stylesheet.java60
1 files changed, 38 insertions, 22 deletions
diff --git a/libjava/classpath/gnu/xml/transform/Stylesheet.java b/libjava/classpath/gnu/xml/transform/Stylesheet.java
index 51accaa3b9a..73b22969114 100644
--- a/libjava/classpath/gnu/xml/transform/Stylesheet.java
+++ b/libjava/classpath/gnu/xml/transform/Stylesheet.java
@@ -408,7 +408,7 @@ class Stylesheet
{
if (debug)
System.err.println("getTemplate: mode="+mode+" context="+context);
- Set candidates = new TreeSet();
+ Template selected = null;
for (Iterator j = templates.iterator(); j.hasNext(); )
{
Template t = (Template) j.next();
@@ -426,10 +426,21 @@ class Stylesheet
}
//System.err.println("\t"+context+" "+t+"="+isMatch);
if (isMatch)
- candidates.add(t);
+ {
+ // Conflict resolution
+ // @see http://www.w3.org/TR/xslt#conflict
+ if (selected == null)
+ selected = t;
+ else
+ {
+ if (t.precedence < selected.precedence ||
+ t.priority < selected.priority)
+ continue;
+ selected = t;
+ }
+ }
}
- //System.err.println("\tcandidates="+candidates);
- if (candidates.isEmpty())
+ if (selected == null)
{
// Apply built-in template
// Current template is unchanged
@@ -451,32 +462,39 @@ class Stylesheet
return null;
}
}
- else
- {
- Template t = (Template) candidates.iterator().next();
- // Set current template
- currentTemplate = t;
- if (debug)
- System.err.println("\ttemplate="+t+" context="+context);
- return t.node;
- }
+ // Set current template
+ currentTemplate = selected;
+ if (debug)
+ System.err.println("\ttemplate="+currentTemplate+" context="+context);
+ return currentTemplate.node;
}
TemplateNode getTemplate(QName mode, QName name)
throws TransformerException
{
- Set candidates = new TreeSet();
+ Template selected = null;
for (Iterator j = templates.iterator(); j.hasNext(); )
{
Template t = (Template) j.next();
boolean isMatch = t.matches(name);
if (isMatch)
- candidates.add(t);
+ {
+ // Conflict resolution
+ // @see http://www.w3.org/TR/xslt#conflict
+ if (selected == null)
+ selected = t;
+ else
+ {
+ if (t.precedence < selected.precedence ||
+ t.priority < selected.priority)
+ continue;
+ selected = t;
+ }
+ }
}
- if (candidates.isEmpty())
+ if (selected == null)
return null;
- Template t = (Template) candidates.iterator().next();
- return t.node;
+ return selected.node;
}
/**
@@ -504,11 +522,9 @@ class Stylesheet
String p = getAttribute(attrs, "priority");
String mm = getAttribute(attrs, "mode");
QName mode = (mm == null) ? null : getQName(mm);
- double priority = (p == null) ? Template.DEFAULT_PRIORITY :
- Double.parseDouble(p);
Node children = node.getFirstChild();
return new Template(this, name, match, parse(children),
- precedence, priority, mode);
+ precedence, p, mode);
}
/**
@@ -799,7 +815,7 @@ class Stylesheet
templates.add(new Template(this, null, new Root(),
parse(rootClone),
precedence,
- Template.DEFAULT_PRIORITY,
+ null,
null));
}
else
OpenPOWER on IntegriCloud