package org.wamblee.xml;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
transform(source, result, aXslt);
return (Document) result.getNode();
}
+
+ /**
+ * Transforms a document to a text output. This supports XSLT transformations
+ * that result in text documents.
+ * @param aDocument Document to transform.
+ * @param aXslt XSL transformation.
+ * @return Transformed document.
+ */
+ public String textTransform(byte[] aDocument, InputResource aXslt) throws IOException, TransformerException {
+ Source source = new StreamSource(new ByteArrayInputStream(aDocument));
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(os);
+ transform(source, result, aXslt);
+ return new String(os.toByteArray());
+ }
/**
* Transforms a document using XSLT.