简体   繁体   English

如何使用XSLT将我的Scala XML对象(Elem类)转换为HTML?

[英]How do I transform my Scala XML object (of class Elem) to HTML using XSLT?

I have a small piece of code that, given the paths of my XML and XSLT files, outputs an HTML file in the provided path. 我有一小段代码,给出我的XML和XSLT文件的路径,然后在提供的路径中输出HTML文件。 It goes like this: 它是这样的:

  try {
       val tFactory: TransformerFactory = TransformerFactory.newInstance
       val transformer: Transformer = tFactory.newTransformer(new StreamSource("<PATH TO XSL>"))
       transformer.transform(new StreamSource("<PATH TO XML>"), new StreamResult(new FileOutputStream("PATH TO HTML")))
 } catch {
       case e: Exception => e.printStackTrace
 }

Now, instead of an XML file as an input, I want to input a Scala Elem object. 现在,我要输入一个Scala Elem对象,而不是XML文件作为输入。 How do I make that possible? 我如何才能做到这一点?

You need to create string from your element. 您需要从您的元素创建字符串。

val xml = <elem/>
transformer.transform(new StreamSource(new StringReader(xml.toString())), new StreamResult(writer))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM