public void prepareAttributes() throws XPathException { AttributeCollection atts = getAttributeList(); String nameAtt = null; String namespaceAtt = null; String selectAtt = null; String separatorAtt = null; String validationAtt = null; String typeAtt = null; for (int a = 0; a < atts.getLength(); a++) { int nc = atts.getNameCode(a); String f = getNamePool().getClarkName(nc); if (f == StandardNames.NAME) { nameAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.NAMESPACE) { namespaceAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.SELECT) { selectAtt = atts.getValue(a); } else if (f == StandardNames.SEPARATOR) { separatorAtt = atts.getValue(a); } else if (f == StandardNames.VALIDATION) { validationAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.TYPE) { typeAtt = Whitespace.trim(atts.getValue(a)); } else { checkUnknownAttribute(nc); } } if (nameAtt == null) { reportAbsence("name"); return; } attributeName = makeAttributeValueTemplate(nameAtt); if (attributeName instanceof StringLiteral) { if (!getConfiguration() .getNameChecker() .isQName(((StringLiteral) attributeName).getStringValue())) { invalidAttributeName("Attribute name " + Err.wrap(nameAtt) + " is not a valid QName"); } if (nameAtt.equals("xmlns")) { if (namespace == null) { invalidAttributeName("Invalid attribute name: xmlns"); } } if (nameAtt.startsWith("xmlns:")) { if (namespaceAtt == null) { invalidAttributeName("Invalid attribute name: " + Err.wrap(nameAtt)); } else { // ignore the prefix "xmlns" nameAtt = nameAtt.substring(6); attributeName = new StringLiteral(nameAtt); } } } if (namespaceAtt != null) { namespace = makeAttributeValueTemplate(namespaceAtt); if (namespace instanceof StringLiteral) { if (!AnyURIValue.isValidURI(((StringLiteral) namespace).getStringValue())) { compileError("The value of the namespace attribute must be a valid URI", "XTDE0865"); } } } if (selectAtt != null) { select = makeExpression(selectAtt); } if (separatorAtt == null) { if (selectAtt == null) { separator = new StringLiteral(StringValue.EMPTY_STRING); } else { separator = new StringLiteral(StringValue.SINGLE_SPACE); } } else { separator = makeAttributeValueTemplate(separatorAtt); } if (validationAtt != null) { validationAction = Validation.getCode(validationAtt); if (validationAction != Validation.STRIP && !getExecutable().isSchemaAware()) { validationAction = Validation.STRIP; compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660"); } if (validationAction == Validation.INVALID) { compileError("Invalid value of validation attribute", "XTSE0020"); validationAction = getContainingStylesheet().getDefaultValidation(); } } else { validationAction = getContainingStylesheet().getDefaultValidation(); } if (typeAtt != null) { if (!getExecutable().isSchemaAware()) { compileError( "The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660"); } else { SchemaType type = getSchemaType(typeAtt); if (type == null) { compileError("Unknown attribute type " + typeAtt, "XTSE1520"); } else { if (type.isSimpleType()) { schemaType = (SimpleType) type; } else { compileError("Type annotation for attributes must be a simple type", "XTSE1530"); type = null; } } validationAction = Validation.BY_TYPE; } } if (typeAtt != null && validationAtt != null) { compileError("The validation and type attributes are mutually exclusive", "XTSE1505"); validationAction = getContainingStylesheet().getDefaultValidation(); schemaType = null; } }
public void prepareAttributes() throws XPathException { AttributeCollection atts = getAttributeList(); for (int a = 0; a < atts.getLength(); a++) { int nc = atts.getNameCode(a); String f = getNamePool().getClarkName(nc); if (f.equals(StandardNames.MODE)) { modeAtt = Whitespace.trim(atts.getValue(a)); } else if (f.equals(StandardNames.NAME)) { nameAtt = Whitespace.trim(atts.getValue(a)); } else if (f.equals(StandardNames.MATCH)) { matchAtt = atts.getValue(a); } else if (f.equals(StandardNames.PRIORITY)) { priorityAtt = Whitespace.trim(atts.getValue(a)); } else if (f.equals(StandardNames.AS)) { asAtt = atts.getValue(a); } else { checkUnknownAttribute(nc); } } try { if (modeAtt == null) { modeNames = new StructuredQName[1]; modeNames[0] = Mode.DEFAULT_MODE_NAME; } else { if (matchAtt == null) { compileError( "The mode attribute must be absent if the match attribute is absent", "XTSE0500"); } // mode is a space-separated list of mode names, or "#default", or "#all" int count = 0; boolean allModes = false; StringTokenizer st = new StringTokenizer(modeAtt, " \t\n\r", false); while (st.hasMoreTokens()) { st.nextToken(); count++; } if (count == 0) { compileError("The mode attribute must not be empty", "XTSE0550"); } modeNames = new StructuredQName[count]; count = 0; st = new StringTokenizer(modeAtt, " \t\n\r", false); while (st.hasMoreTokens()) { String s = st.nextToken(); StructuredQName mname; if ("#default".equals(s)) { mname = Mode.DEFAULT_MODE_NAME; } else if ("#all".equals(s)) { allModes = true; mname = Mode.ALL_MODES; } else { mname = makeQName(s); } for (int e = 0; e < count; e++) { if (modeNames[e].equals(mname)) { compileError("In the list of modes, the value " + s + " is duplicated", "XTSE0550"); } } modeNames[count++] = mname; } if (allModes && (count > 1)) { compileError("mode='#all' cannot be combined with other modes", "XTSE0550"); } } } catch (NamespaceException err) { compileError(err.getMessage(), "XTSE0280"); } catch (XPathException err) { if (err.getErrorCodeLocalPart() == null) { err.setErrorCode("XTSE0280"); } else if (err.getErrorCodeLocalPart().equals("XTSE0020")) { err.setErrorCode("XTSE0550"); } err.setIsStaticError(true); compileError(err); } try { if (nameAtt != null) { StructuredQName qName = makeQName(nameAtt); setObjectName(qName); diagnosticId = nameAtt; } } catch (NamespaceException err) { compileError(err.getMessage(), "XTSE0280"); } catch (XPathException err) { if (err.getErrorCodeLocalPart() == null) { err.setErrorCode("XTSE0280"); } err.setIsStaticError(true); compileError(err); } prioritySpecified = (priorityAtt != null); if (prioritySpecified) { if (matchAtt == null) { compileError( "The priority attribute must be absent if the match attribute is absent", "XTSE0500"); } try { // it's got to be a valid decimal, but we want it as a double, so parse it twice if (!DecimalValue.castableAsDecimal(priorityAtt)) { compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530"); } priority = Double.parseDouble(priorityAtt); } catch (NumberFormatException err) { // shouldn't happen compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530"); } } if (matchAtt != null) { match = makePattern(matchAtt); if (diagnosticId == null) { diagnosticId = "match=\"" + matchAtt + '\"'; if (modeAtt != null) { diagnosticId += " mode=\"" + modeAtt + '\"'; } } } if (match == null && nameAtt == null) compileError("xsl:template must have a name or match attribute (or both)", "XTSE0500"); if (asAtt != null) { requiredType = makeSequenceType(asAtt); } }