Templates templates = getSource(factory, stylesheet);
Templates templates; if(Type.subTypeOf(stylesheetItem.getType(), Type.NODE)) { NodeValue stylesheetNode = (NodeValue)stylesheetItem; templates = getSource(factory, stylesheetNode); } else { String stylesheet = stylesheetItem.getStringValue(); templates = getSource(factory, stylesheet); }
	public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {		if(args[0].getLength() == 0)			return Sequence.EMPTY_SEQUENCE;		Item inputNode = args[0].itemAt(0);		String stylesheet = args[1].getStringValue();		Node options = null;		if(args[2].getLength() > 0)			options = ((NodeValue)args[2].itemAt(0)).getNode();				SAXTransformerFactory factory = (SAXTransformerFactory)SAXTransformerFactory.newInstance();		TransformerHandler handler;		try {			Templates templates = getSource(factory, stylesheet);			handler = factory.newTransformerHandler(templates);			if(options != null)				parseParameters(options, handler.getTransformer());		} catch (TransformerConfigurationException e) {			throw new XPathException("Unable to set up transformer: " + e.getMessage(), e);		}				context.pushDocumentContext();		MemTreeBuilder builder = context.getDocumentBuilder();		Receiver receiver = new Receiver(builder);		SAXResult result = new SAXResult(receiver);		handler.setResult(result);				try {			handler.startDocument();			inputNode.toSAX(context.getBroker(), handler);			handler.endDocument();		} catch (SAXException e) {			throw new XPathException("SAX exception while transforming node: " + e.getMessage(), e);		}		Node first = builder.getDocument().getFirstChild();		context.popDocumentContext();		return (NodeValue)first;	}