<program>
<match>star.*gate</match>
</program>
+
+ <program>
+ <match>six.*feet.*under</match>
+ </program>
<program>
<match>battlestar</match>
<xsl:template match="program">
<xsl:call-template name="addProgramInfo"/>
</xsl:template>
+
<xsl:template match="interesting">
<xsl:call-template name="programTable"/>
<xsl:apply-templates select="category"/>
</xsl:template>
+
<xsl:template match="category">
<xsl:text>Category: </xsl:text><xsl:value-of select="@name"/>
+ <xsl:value-of select="$newline"/>
+ <xsl:value-of select="$newline"/>
<xsl:call-template name="programTable"/>
</xsl:template>
+
</xsl:stylesheet>
<program>
<name>Brainiac</name>
<description>Humor</description>
- <keywords>
- science
- </keywords>
+ <keywords>science</keywords>
<channel>Discovery Channel</channel>
<interval>
<begin>23:30</begin>
<program>
<name>Andere tijden</name>
<description>Documentaire</description>
- <keywords>
-
- </keywords>
+ <keywords>docu</keywords>
<channel>Nederland 1</channel>
<interval>
<begin>23:30</begin>
} catch (NotificationException e) {
throw new RuntimeException(e);
}
- sendMail(executor);
}
/**
String htmlText = transformReport( aReport, new FileResource(new File(_htmlXslt)) );
String plainText = transformReport( aReport, new FileResource(new File(_textXslt)) );
+
+
mail.setHtmlMsg(htmlText);
mail.setTextMsg(plainText);
*/
private String transformReport( Element aReport, InputResource aXslt ) throws IOException, TransformerException {
String reportXmlText = aReport.asXML();
- Document document = new XSLT().transform(reportXmlText.getBytes(), aXslt);
- ByteArrayOutputStream transformed = new ByteArrayOutputStream();
- XMLSerializer serializer = new XMLSerializer(transformed, new OutputFormat());
- serializer.serialize(document);
- return transformed.toString();
+ return new XSLT().textTransform(reportXmlText.getBytes(), aXslt);
}
}
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.