Exemple #1
0
  public void prepareAttributes() throws XPathException {

    String disableAtt = null;

    AttributeCollection atts = getAttributeList();

    for (int a = 0; a < atts.getLength(); a++) {
      String f = atts.getQName(a);
      if (f.equals(StandardNames.DISABLE_OUTPUT_ESCAPING)) {
        disableAtt = Whitespace.trim(atts.getValue(a));
      } else {
        checkUnknownAttribute(atts.getNodeName(a));
      }
    }

    if (disableAtt != null) {
      if (disableAtt.equals("yes")) {
        disable = true;
      } else if (disableAtt.equals("no")) {
        disable = false;
      } else {
        compileError("disable-output-escaping attribute must be either 'yes' or 'no'", "XTSE0020");
      }
    }
  }
Exemple #2
0
  public void prepareAttributes() throws XPathException {

    AttributeCollection atts = getAttributeList();
    overrideAtt = "yes";
    for (int a = 0; a < atts.getLength(); a++) {
      String f = atts.getQName(a);
      if (f.equals(StandardNames.NAME)) {
        nameAtt = Whitespace.trim(atts.getValue(a));
        assert (nameAtt != null);
        if (nameAtt.indexOf(':') < 0) {
          compileError("Function name must have a namespace prefix", "XTSE0740");
        }
        try {
          setObjectName(makeQName(nameAtt));
        } catch (NamespaceException err) {
          compileError(err.getMessage(), "XTSE0280");
        } catch (XPathException err) {
          compileError(err);
        }
      } else if (f.equals(StandardNames.AS)) {
        asAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.OVERRIDE)) {
        overrideAtt = Whitespace.trim(atts.getValue(a));
        if ("yes".equals(overrideAtt)) {
          override = true;
        } else if ("no".equals(overrideAtt)) {
          override = false;
        } else {
          override = true;
          compileError("override must be 'yes' or 'no'", "XTSE0020");
        }
      } else if (f.equals("memo-function") && atts.getURI(a).equals(NamespaceConstant.SAXON)) {
        String memoAtt = Whitespace.trim(atts.getValue(a));
        if ("yes".equals(memoAtt)) {
          memoFunction = true;
        } else if ("no".equals(memoAtt)) {
          memoFunction = false;
        } else {
          compileError("saxon:memo-function must be 'yes' or 'no'", "XTSE0020");
        }
      } else {
        checkUnknownAttribute(atts.getNodeName(a));
      }
    }

    if (nameAtt == null) {
      reportAbsence("name");
      nameAtt = "xsl:unnamed-function-" + generateId();
    }

    if (asAtt == null) {
      resultType = SequenceType.ANY_SEQUENCE;
    } else {
      resultType = makeSequenceType(asAtt);
    }

    functionName = nameAtt;
  }
Exemple #3
0
  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++) {
      String f = atts.getQName(a);
      if (f.equals(StandardNames.NAME)) {
        nameAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.NAMESPACE)) {
        namespaceAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.SELECT)) {
        selectAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.SEPARATOR)) {
        separatorAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.VALIDATION)) {
        validationAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.TYPE)) {
        typeAtt = Whitespace.trim(atts.getValue(a));
      } else {
        checkUnknownAttribute(atts.getNodeName(a));
      }
    }

    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 (!StandardURIChecker.getInstance()
            .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 && !getPreparedStylesheet().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 (!getPreparedStylesheet().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");
          }
        }
        validationAction = Validation.BY_TYPE;
      }
    }

    if (typeAtt != null && validationAtt != null) {
      compileError("The validation and type attributes are mutually exclusive", "XTSE1505");
      validationAction = getContainingStylesheet().getDefaultValidation();
      schemaType = null;
    }
  }