/** * Get the number of arguments declared by this function (that is, its arity). * * @return the arity of the function */ public int getNumberOfArguments() { if (numberOfArguments == -1) { numberOfArguments = 0; AxisIterator kids = iterateAxis(Axis.CHILD); while (true) { Item child = kids.next(); if (child instanceof XSLParam) { numberOfArguments++; } else { return numberOfArguments; } } } return numberOfArguments; }
public void validate(Declaration decl) throws XPathException { // 2.0 spec has reverted to the 1.0 rule that xsl:text may not have child elements AxisIterator kids = iterateAxis(Axis.CHILD); value = StringValue.EMPTY_STRING; while (true) { Item child = kids.next(); if (child == null) { break; } else if (child instanceof StyleElement) { ((StyleElement) child).compileError("xsl:text must not contain child elements", "XTSE0010"); return; } else { value = StringValue.makeStringValue(child.getStringValueCS()); // continue; } } super.validate(decl); }
/** * Set the definitions of the parameters in the compiled function, as an array. * * @param fn the compiled object representing the user-written function */ public void setParameterDefinitions(UserFunction fn) { UserFunctionParameter[] params = new UserFunctionParameter[getNumberOfArguments()]; fn.setParameterDefinitions(params); int count = 0; AxisIterator kids = iterateAxis(Axis.CHILD); while (true) { NodeInfo node = kids.next(); if (node == null) { return; } if (node instanceof XSLParam) { UserFunctionParameter param = new UserFunctionParameter(); params[count++] = param; param.setRequiredType(((XSLParam) node).getRequiredType()); param.setVariableQName(((XSLParam) node).getVariableQName()); param.setSlotNumber(((XSLParam) node).getSlotNumber()); ((XSLParam) node).fixupBinding(param); int refs = ExpressionTool.getReferenceCount(fn.getBody(), param, false); param.setReferenceCount(refs); } } }
public Expression compile(Executable exec, Declaration decl) throws XPathException { NamespaceResolver nsContext = null; // deal specially with the case where the attribute name is known statically if (attributeName instanceof StringLiteral) { String qName = Whitespace.trim(((StringLiteral) attributeName).getStringValue()); String[] parts; try { parts = getConfiguration().getNameChecker().getQNameParts(qName); } catch (QNameException e) { // This can't happen, because of previous checks return null; } if (namespace == null) { String nsuri = ""; if (!parts[0].equals("")) { nsuri = getURIForPrefix(parts[0], false); if (nsuri == null) { undeclaredNamespaceError(parts[0], "XTSE0280"); return null; } } NodeName attributeName = new FingerprintedQName(parts[0], nsuri, parts[1]); attributeName.allocateNameCode(getNamePool()); FixedAttribute inst = new FixedAttribute(attributeName, validationAction, schemaType); inst.setContainer(this); // temporarily compileContent(exec, decl, inst, separator); return inst; } else if (namespace instanceof StringLiteral) { String nsuri = ((StringLiteral) namespace).getStringValue(); if (nsuri.equals("")) { parts[0] = ""; } else if (parts[0].equals("")) { // Need to choose an arbitrary prefix // First see if the requested namespace is declared in the stylesheet AxisIterator iter = iterateAxis(Axis.NAMESPACE); while (true) { NodeInfo ns = iter.next(); if (ns == null) { break; } if (ns.getStringValue().equals(nsuri)) { parts[0] = ns.getLocalPart(); break; } } // Otherwise see the URI is known to the namepool if (parts[0].equals("")) { String p = getNamePool().suggestPrefixForURI(((StringLiteral) namespace).getStringValue()); if (p != null) { parts[0] = p; } } // Otherwise choose something arbitrary. This will get changed // if it clashes with another attribute if (parts[0].equals("")) { parts[0] = "ns0"; } } NodeName nameCode = new FingerprintedQName(parts[0], nsuri, parts[1]); nameCode.allocateNameCode(getNamePool()); FixedAttribute inst = new FixedAttribute(nameCode, validationAction, schemaType); compileContent(exec, decl, inst, separator); return inst; } } else { // if the namespace URI must be deduced at run-time from the attribute name // prefix, we need to save the namespace context of the instruction if (namespace == null) { nsContext = makeNamespaceContext(); } } ComputedAttribute inst = new ComputedAttribute( attributeName, namespace, nsContext, validationAction, schemaType, false); compileContent(exec, decl, inst, separator); return inst; }