serializer.setProperties(outputProperties);
    public Sequence eval(Sequence[] args, Sequence contextSequence)            throws XPathException {        if (args[0].getLength() == 0)            return Sequence.EMPTY_SEQUENCE;                // check the file output path        String path = args[1].itemAt(0).getStringValue();        File file = new File(path);        if (file.isDirectory()) {            LOG.debug("Output file is a directory: " + file.getAbsolutePath());            return BooleanValue.FALSE;        }        if (file.exists() && !file.canWrite()) {            LOG.debug("Cannot write to file " + file.getAbsolutePath());            return BooleanValue.FALSE;        }                // parse serialization options        Properties outputProperties = new Properties();        outputProperties.setProperty(OutputKeys.INDENT, "yes");        outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");        for (SequenceIterator i = args[2].iterate(); i.hasNext(); ) {             String opt[] = Pragma.parseKeyValuePair(i.nextItem().getStringValue());            outputProperties.setProperty(opt[0], opt[1]);        }                // serialize the node set        SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);        try {            String encoding = outputProperties.getProperty(OutputKeys.ENCODING, "UTF-8");            Writer writer = new OutputStreamWriter(new FileOutputStream(file), encoding);            sax.setOutput(writer, outputProperties);            Serializer serializer = context.getBroker().getSerializer();            serializer.reset();            serializer.setReceiver(sax);            sax.startDocument();                        for (SequenceIterator i = args[0].iterate(); i.hasNext(); ) {                NodeValue next = (NodeValue) i.nextItem();                serializer.toSAX(next);            }                        sax.endDocument();            writer.close();        } catch (SAXException e) {            throw new XPathException(getASTNode(), "A problem ocurred while serializing the node set: " + e.getMessage(), e);        } catch (IOException e) {            throw new XPathException(getASTNode(), "A problem ocurred while serializing the node set: " + e.getMessage(), e);        } finally {            SerializerPool.getInstance().returnObject(sax);        }        return BooleanValue.TRUE;    }