protected AttributeSet[] getAttributeSets(String use, List list)
            throws XPathException {

        if (list == null) {
            list = new ArrayList(4);
        }

        XSLStylesheet stylesheet = getPrincipalStylesheet();
        List toplevel = stylesheet.getTopLevel();

        StringTokenizer st = new StringTokenizer(use, " \t\n\r", false);
        while (st.hasMoreTokens()) {
            String asetname = st.nextToken();
            StructuredQName fprint;
            try {
                fprint = makeQName(asetname);
            } catch (NamespaceException err) {
                compileError(err.getMessage(), "XTSE0710");
                fprint = null;
            } catch (XPathException err) {
                compileError(err.getMessage(), "XTSE0710");
                fprint = null;
            }
            boolean found = false;

            // search for the named attribute set, using all of them if there are several with the
            // same name

            for (int i = 0; i < toplevel.size(); i++) {
                if (toplevel.get(i) instanceof XSLAttributeSet) {
                    XSLAttributeSet t = (XSLAttributeSet)toplevel.get(i);
                    if (t.getAttributeSetName().equals(fprint)) {
                        list.add(t);
                        found = true;
                    }
                }
            }

            if (!found) {
                compileError("No attribute-set exists named " + asetname, "XTSE0710");
            }
        }

        AttributeSet[] array = new AttributeSet[list.size()];
        for (int i = 0; i < list.size(); i++) {
            XSLAttributeSet aset = (XSLAttributeSet)list.get(i);
            aset.incrementReferenceCount();
            array[i] = aset.getInstruction();
        }
        return array;
    }