}
public Expression compile(Executable exec) throws XPathException
{
Boolean preserve = Boolean.valueOf(getFingerprint() == StandardNames.XSL_PRESERVE_SPACE);
Mode stripperRules = getPrincipalStylesheet().getStripperRules();
// elements is a space-separated list of element names
StringTokenizer st = new StringTokenizer(elements, " \t\n\r", false);
while (st.hasMoreTokens()) {
String s = st.nextToken();
NodeTestPattern pat = new NodeTestPattern();
// following information is used in conflict warnings
pat.setOriginalText(s);
pat.setSystemId(getSystemId());
pat.setLineNumber(getLineNumber());
NodeTest nt;
if (s.equals("*")) {
nt = AnyNodeTest.getInstance();
pat.setNodeTest(nt);
stripperRules.addRule(
pat,
preserve,
getPrecedence(),
-0.5, true);
} else if (s.endsWith(":*")) {
if (s.length()==2) {
compileError("No prefix before ':*'");
}
String prefix = s.substring(0, s.length()-2);
String uri = getURIForPrefix(prefix, false);
nt = new NamespaceTest(
getNamePool(),
Type.ELEMENT,
uri);
pat.setNodeTest(nt);
stripperRules.addRule(
pat,
preserve,
getPrecedence(),
-0.25, true);
} else if (s.startsWith("*:")) {
if (s.length()==2) {
compileError("No local name after '*:'");
}
String localname = s.substring(2);
nt = new LocalNameTest(
getNamePool(),
Type.ELEMENT,
localname);
pat.setNodeTest(nt);
stripperRules.addRule(
pat,
preserve,
getPrecedence(),
-0.25, true);
} else {
String prefix;
String localName = null;
String uri = null;
try {
String[] parts = getConfiguration().getNameChecker().getQNameParts(s);
prefix = parts[0];
if (parts[0].equals("")) {
uri = getDefaultXPathNamespace();
} else {
uri = getURIForPrefix(prefix, false);
if (uri == null) {
undeclaredNamespaceError(prefix, "XTSE0280");
return null;
}
}
localName = parts[1];
} catch (QNameException err) {
compileError("Element name " + s + " is not a valid QName", "XTSE0280");
return null;
}
NamePool target = getNamePool();
int nameCode = target.allocate("", uri, localName);
nt = new NameTest(Type.ELEMENT, nameCode, getNamePool());
pat.setNodeTest(nt);
stripperRules.addRule(
pat,
preserve,
getPrecedence(),
0, true);
}