public void validate() throws XPathException {

        //checkWithinTemplate();

        // get the Mode object
        if (!useCurrentMode) {
            mode = getPrincipalStylesheet().getRuleManager().getMode(modeName, true);
        }

        // handle sorting if requested

        AxisIterator kids = iterateAxis(Axis.CHILD);
        while (true) {
            NodeInfo child = (NodeInfo)kids.next();
            if (child == null) {
                break;
            }
            if (child instanceof XSLSort) {
                // no-op
            } else if (child instanceof XSLWithParam) {
                // usesParams = true;
            } else if (child.getNodeKind() == Type.TEXT) {
                    // with xml:space=preserve, white space nodes may still be there
                if (!Whitespace.isWhite(child.getStringValueCS())) {
                    compileError("No character data is allowed within xsl:apply-templates", "XTSE0010");
                }
            } else {
                compileError("Invalid element within xsl:apply-templates", "XTSE0010");
            }
        }

        if (select==null) {
            select = new AxisExpression(Axis.CHILD, null);
            implicitSelect = true;
        }

        select = typeCheck("select", select);
        try {
            RoleLocator role =
                new RoleLocator(RoleLocator.INSTRUCTION, "xsl:apply-templates/select", 0);
            //role.setSourceLocator(new ExpressionLocation(this));
            role.setErrorCode("XTTE0520");
            select = TypeChecker.staticTypeCheck(select,
                                        SequenceType.NODE_SEQUENCE,
                                        false, role, makeExpressionVisitor());
        } catch (XPathException err) {
            compileError(err);
        }

    }