private static void exportRuleJS(Rule rule, FastStringBuffer fsb) { String which = rule.getAction() == Stripper.STRIP ? "true" : "false"; NodeTest test = (NodeTest)rule.getPattern().getItemType(); if (test instanceof NodeKindTest) { // elements="*" fsb.append("return " + which + ";"); } else if (test instanceof NameTest) { fsb.append("if (uri=='" + test.getMatchingNodeName().getURI() + "' && local=='" + test.getMatchingNodeName().getLocalPart() + "') return " + which + ";" ); } else if (test instanceof NamespaceTest) { fsb.append("if (uri=='" + ((NamespaceTest)test).getNamespaceURI() + "') return " + which + ";"); } else if (test instanceof LocalNameTest) { fsb.append("if (local=='" + ((LocalNameTest) test).getLocalName() + "') return " + which + ";"); } else { throw new IllegalStateException("Cannot export " + test.getClass()); } } }
private static void exportRuleJS(Rule rule, FastStringBuffer fsb) { String which = rule.getAction() == Stripper.STRIP ? "true" : "false"; NodeTest test = (NodeTest)rule.getPattern().getItemType(); if (test instanceof NodeKindTest) { // elements="*" fsb.append("return " + which + ";"); } else if (test instanceof NameTest) { fsb.append("if (uri=='" + test.getMatchingNodeName().getURI() + "' && local=='" + test.getMatchingNodeName().getLocalPart() + "') return " + which + ";" ); } else if (test instanceof NamespaceTest) { fsb.append("if (uri=='" + ((NamespaceTest)test).getNamespaceURI() + "') return " + which + ";"); } else if (test instanceof LocalNameTest) { fsb.append("if (local=='" + ((LocalNameTest) test).getLocalName() + "') return " + which + ";"); } else { throw new IllegalStateException("Cannot export " + test.getClass()); } } }
private lux.xpath.NodeTest nodeTestFor (NodeTest nodeTest) { if (nodeTest == null) { return new lux.xpath.NodeTest(ValueType.NODE); } if (nodeTest instanceof DocumentNodeTest) { return nodeTestFor ((DocumentNodeTest) nodeTest); } int nameCode = nodeTest.getFingerprint(); ValueType nodeType = valueTypeForItemType(nodeTest); if (nameCode >= 0) { // matches a single node name return new lux.xpath.NodeTest (nodeType, qnameForNameCode(nameCode)); } else { // matches multiple node names if (nodeTest instanceof LocalNameTest) { return new lux.xpath.NodeTest (nodeType, new QName(null, ((LocalNameTest)nodeTest).getLocalName(), "*")); } if (nodeTest instanceof NamespaceTest) { NamespaceTest namespaceTest = (NamespaceTest) nodeTest; String namespace = namespaceTest.getNamespaceURI(); String prefix = getPrefixForNamespace (namespace); QName qname = new QName(namespace, "*", prefix); addNamespaceDeclaration(qname); return new lux.xpath.NodeTest (nodeType, qname); } IntSet nameCodes = nodeTest.getRequiredNodeNames(); if (nameCodes == IntUniversalSet.getInstance()) { return new lux.xpath.NodeTest (nodeType); } throw new IllegalArgumentException("Unsupported node test: " + nodeTest.toString()); } }
if (test.getPrimitiveType() == Type.ELEMENT) { NamespaceTest nt = (NamespaceTest) test; stepper = new FollowingElementStepper<>(start, nt.getNamespaceURI(), null); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);
if (test.getPrimitiveType() == Type.ELEMENT) { NamespaceTest nt = (NamespaceTest) test; stepper = new FollowingElementStepper<>(start, nt.getNamespaceURI(), null); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);