X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fsrc%2Forg%2Fwamblee%2Fxml%2FXSLT.java;h=ae603976b6de126e8a1ac22a3880fb76d1599f7c;hb=4396b19804a64ca19cdf6508878ea17332069b72;hp=e7c5fc7643c76c046e06c69c401f67a435df5618;hpb=5b6b49fbe01397461e67238481c84a62c8ed4bef;p=utils diff --git a/support/src/org/wamblee/xml/XSLT.java b/support/src/org/wamblee/xml/XSLT.java index e7c5fc76..ae603976 100644 --- a/support/src/org/wamblee/xml/XSLT.java +++ b/support/src/org/wamblee/xml/XSLT.java @@ -17,6 +17,7 @@ package org.wamblee.xml; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -28,6 +29,7 @@ import javax.xml.transform.TransformerException; 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; @@ -88,6 +90,21 @@ public class XSLT { 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.