/**
  * Get n'th attribute (DOM NamedNodeMap method). In this implementation we number the attributes
  * as follows: 0 - the xmlns:xml namespace declaration 1-n further namespace declarations n+1...
  * "real" attribute declarations
  */
 public Node item(int index) {
   if (index < 0) {
     return null;
   }
   if (index == 0) {
     NamespaceIterator.NamespaceNodeImpl nn =
         new NamespaceIterator.NamespaceNodeImpl(parent, NamespaceConstant.XML_NAMESPACE_CODE, 0);
     return NodeOverNodeInfo.wrap(nn);
   }
   int nscount = getNumberOfNamespaces();
   if (index < nscount) {
     int[] buffer = new int[8];
     int[] nsList = parent.getDeclaredNamespaces(buffer);
     int nscode = nsList[index - 1];
     NamespaceIterator.NamespaceNodeImpl nn =
         new NamespaceIterator.NamespaceNodeImpl(parent, nscode, index);
     return NodeOverNodeInfo.wrap(nn);
   }
   int pos = 0;
   int attNr = (index - nscount);
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (true) {
     NodeInfo att = (NodeInfo) atts.next();
     if (att == null) {
       return null;
     }
     if (pos == attNr) {
       return NodeOverNodeInfo.wrap(att);
     }
     pos++;
   }
 }
Ejemplo n.º 2
0
 /**
  * Constructor for use in free-standing Java applications. Must be used with care, since functions
  * dependent on a Controller will not be available.
  */
 public XPathContextMajor(Item item, Configuration config) {
   controller = new Controller(config);
   controller.setExecutable(new Executable());
   AxisIterator iter = SingletonIterator.makeIterator(item);
   iter.next();
   currentIterator = iter;
   origin = controller;
 }
 /** Get number of attributes and namespaces (DOM NamedNodeMap method). */
 public int getLength() {
   int length = 0;
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (atts.next() != null) {
     length++;
   }
   return getNumberOfNamespaces() + length;
 }
Ejemplo n.º 4
0
 /**
  * Set all the declared namespaces to be the namespaces that are in-scope for a given node. In
  * addition, the standard namespaces (xml, xslt, saxon) are declared.
  *
  * @param node The node whose in-scope namespaces are to be used as the context namespaces. Note
  *     that this will have no effect unless this node is an element.
  */
 public void setNamespaces(NodeInfo node) {
   namespaces.clear();
   AxisIterator iter = node.iterateAxis(Axis.NAMESPACE);
   while (true) {
     NodeInfo ns = (NodeInfo) iter.next();
     if (ns == null) {
       return;
     }
     declareNamespace(ns.getLocalPart(), ns.getStringValue());
   }
 }
 /** Get named attribute (DOM NamedNodeMap method) */
 public Node getNamedItem(String name) {
   if (name.equals("xmlns")) {
     int[] nsarray = parent.getDeclaredNamespaces(null);
     for (int i = 0; i < nsarray.length; i++) {
       if (nsarray[i] == -1) {
         return null;
       } else if (((nsarray[i] >> 16) & 0xffff) == 0) {
         NamespaceIterator.NamespaceNodeImpl nn =
             new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
         return NodeOverNodeInfo.wrap(nn);
       }
     }
     return null;
   } else if (name.startsWith("xmlns:")) {
     String prefix = name.substring(6);
     if (prefix.equals("xml")) {
       NamespaceIterator.NamespaceNodeImpl nn =
           new NamespaceIterator.NamespaceNodeImpl(parent, NamespaceConstant.XML_CODE, 0);
       return NodeOverNodeInfo.wrap(nn);
     }
     int[] buffer = new int[8];
     int[] nsarray = parent.getDeclaredNamespaces(buffer);
     for (int i = 0; i < nsarray.length; i++) {
       if (nsarray[i] == -1) {
         return null;
       } else if (prefix.equals(parent.getNamePool().getPrefixFromNamespaceCode(nsarray[i]))) {
         NamespaceIterator.NamespaceNodeImpl nn =
             new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
         return NodeOverNodeInfo.wrap(nn);
       }
     }
     return null;
   } else {
     AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
     while (true) {
       NodeInfo att = (NodeInfo) atts.next();
       if (att == null) {
         return null;
       }
       if (name.equals(att.getDisplayName())) {
         return NodeOverNodeInfo.wrap(att);
       }
     }
   }
 }
Ejemplo n.º 6
0
  public void validate() throws TransformerConfigurationException {
    checkWithinTemplate();

    // 2.0 spec has reverted to the 1.0 rule that xsl:text may not have child elements
    AxisIterator kids = iterateAxis(Axis.CHILD);
    while (true) {
      Item child = kids.next();
      if (child == null) {
        value = StringValue.EMPTY_STRING;
        break;
      } else if (child instanceof StyleElement) {
        compileError("xsl:text must not contain child elements", "XT0010");
        return;
      } else {
        value = new StringValue(child.getStringValueCS());
        break;
      }
    }
    super.validate();
  }
 /** Get named attribute (DOM NamedNodeMap method) */
 public Node getNamedItemNS(String uri, String localName) {
   if (uri == null) {
     uri = "";
   }
   if (NamespaceConstant.XMLNS.equals(uri)) {
     return getNamedItem("xmlns:" + localName);
   }
   if (uri.equals("") && localName.equals("xmlns")) {
     return getNamedItem("xmlns");
   }
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (true) {
     NodeInfo att = (NodeInfo) atts.next();
     if (att == null) {
       return null;
     }
     if (uri.equals(att.getURI()) && localName.equals(att.getLocalPart())) {
       return NodeOverNodeInfo.wrap(att);
     }
   }
 }
Ejemplo n.º 8
0
  public Expression compile(Executable exec) throws XPathException {
    NamespaceResolver nsContext = null;

    int annotation = getTypeAnnotation(schemaType);

    // 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;
          }
        }
        int nameCode = getNamePool().allocate(parts[0], nsuri, parts[1]);
        FixedAttribute inst =
            new FixedAttribute(nameCode, validationAction, schemaType, annotation);
        inst.setContainer(this); // temporarily
        compileContent(exec, 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 = (NodeInfo) 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";
          }
        }
        int nameCode = getNamePool().allocate(parts[0], nsuri, parts[1]);
        FixedAttribute inst =
            new FixedAttribute(nameCode, validationAction, schemaType, annotation);
        compileContent(exec, 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, annotation, false);
    compileContent(exec, inst, separator);
    return inst;
  }
Ejemplo n.º 9
0
 @Override
 protected NodeInfo findNext() {
   return (NodeInfo) iterator.next();
 }