public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
argumentTypeCheck(runtime, args[0]);
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
DOMSource domSource = new DOMSource(((XmlDocument) args[0]).getDocument());
DOMResult result = null;
String stringResult = null;
try{
result = tryXsltTransformation(context, args, domSource, elistener); // DOMResult
if (result.getNode().getFirstChild() == null) {
stringResult = retryXsltTransformation(context, args, domSource, elistener); // StreamResult
}
} catch(TransformerConfigurationException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch(TransformerException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch (IOException ex) {
throw runtime.newRuntimeError(ex.getMessage());
}
switch (elistener.getErrorType()) {
case ERROR:
case FATAL:
throw runtime.newRuntimeError(elistener.getErrorMessage());
case WARNING:
default:
// no-op
}