我在做什么:我正在尝试使用xslt将xml转换为html.
问题:程序正在执行而没有任何错误,它也会生成输出文件,但它不会将xml转换为html.我的猜测是xsl中的for循环不是获取数据.
XSLTTest.java
package JavaXSLTExample;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XSLTTest {
public static void main(String[] args)
{
/*if (args.length != 3)
{
System.err.println("give command as follows : ");
System.err.println("XSLTTest data.xml converted.xsl converted.html");
return;
}*/
String dataXML = "C:\\Users\\Devrath\\Desktop\\XSL\\FileOne.xml";
String inputXSL = "C:\\Users\\Devrath\\Desktop\\XSL\\FileTwo.xsl";
String outputHTML = "C:\\Users\\Devrath\\Desktop\\XSL\\output1.html";
XSLTTest st = new XSLTTest();
try
{
st.transform(dataXML, inputXSL, outputHTML);
}
catch (TransformerConfigurationException e)
{
System.err.println("TransformerConfigurationException");
System.err.println(e);
}
catch (TransformerException e)
{
System.err.println("TransformerException");
System.err.println(e);
}
}
public void transform(String dataXML, String inputXSL, String outputHTML)
throws TransformerConfigurationException,
TransformerException
{
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslStream = new StreamSource(inputXSL);
Transformer transformer = factory.newTransformer(xslStream);
StreamSource in = new StreamSource(dataXML);
StreamResult out = new StreamResult(outputHTML);
transformer.transform(in, out);
System.out.println("The generated HTML file is:" + outputHTML);
}
}
FileOne.xml
Kannada
Karnataka
38M
Dravidian
Telugu
Andra Pradesh
74M
Dravidian
Tamil
TamilNadu
61M
Dravidian
Malayalam
Kerela
33M
Dravidian
Hindi
Andaman and Nicobar Islands, North india, Parts of North east
442M
Indo Aryan
Assamese
Assam, Arunachal Pradesh
13M
Indo Aryan
FileTwo.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Language | Family/Origin | No. of speakers | Region |
---|---|---|---|
Output.html
Language | Family/Origin | No. of speakers | Region |
---|