你看本论坛的页面是html的吗?要想得到html代码,些个程序把吧!
给你个例子:
public String getParesdHtml(String xmlSource){
       try{
SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory
.newInstance();
         XMLFilter filter = stf.newXMLFilter(new StreamSource(xslFile));
         Transformer transformer = stf.newTransformer();
         StringReader srcReader = new StringReader(xmlSource);
         SAXSource src = new SAXSource(filter, new InputSource(srcReader));
         StringWriter sw = new StringWriter();
         StreamResult target = new StreamResult(sw);
         transformer.transform(src, target);
         return sw.toString();
      }
      catch (Exception e) {
e.printStackTrace();
         return "";
      }
}

解决方案 »

  1.   

    对啊,比如csnd这个帖子来说,我察看源代码只是xml文件,如何等得到html文件呢,楼上的写的方法好像是4J解析的吧。用jdom或者dom写的啊
      

  2.   


    import javax.xml.transform.*;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource; /**
       * 这个方法将xml通过样式单转换.
       * @param xmlfile 将要被转换的xml文件路径
       * @param xslfile XSL文件的文件路径
       * @return String 转换后的字符串形式存放的html
       */
      public static String ExecuteXSL(String xmlfile, String xslfile) {
        try {
          ByteArrayOutputStream byteRep = new ByteArrayOutputStream();
          TransformerFactory transformerFactory =
              TransformerFactory.newInstance();
          StreamSource source = new StreamSource(xmlfile);
          StreamResult result = new StreamResult(byteRep);
          StreamSource style = new StreamSource(xslfile);
          Transformer transformer =
              transformerFactory.newTransformer(style);
          transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING,
                                        "GB2312"); //\u8BBE\u7F6E\u7F16\u7801
          transformer.transform(source, result);
          return byteRep.toString();
        }
        catch (Exception e) {
          e.printStackTrace();
          return null;
        }  }
      

  3.   

    这个方法不行啊,好像说是
    javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: stylesheet 要求属性: version at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:805) at untitled3.Untitled1.ExecuteXSL(Untitled1.java:86) at untitled3.Untitled1.main(Untitled1.java:42)Caused by: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: stylesheet 要求属性: version at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:984) at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788) ... 2 moreCaused by: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: stylesheet 要求属性: version at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:980) ... 3 moreCaused by: javax.xml.transform.TransformerException: stylesheet 要求属性: version at org.apache.xalan.processor.ProcessorLRE.startElement(ProcessorLRE.java:209) at org.apache.xalan.processor.StylesheetHandler.startElement(StylesheetHandler.java:668) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972) ... 3 more
      

  4.   


    你的xsl有问题,
    命名空间必须是:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      

  5.   

    不过jdk自带的xml解析api有问题的,不如用dom4j。
      

  6.   

    楼上的兄弟,不行啊,
    我的xsl如下:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
        <HTML>
          <HEAD>
            <TITLE><xsl:value-of select="document/title"/></TITLE>
          </HEAD>
          <BODY>
            <H1><xsl:value-of select="document/title"/></H1>
            <xsl:apply-templates select="document/section"/>
          </BODY>
        </HTML>
      </xsl:template>
      <xsl:template match="section">
        <DIV>
          <H2><xsl:value-of select="title"/></H2>
          <xsl:apply-templates />
        </DIV>
      </xsl:template>  <xsl:template match="p">
        <P><xsl:apply-templates /></P>
      </xsl:template>  <xsl:template match="list">
        <UL>
          <xsl:for-each select="item">
            <LI><xsl:apply-templates /></LI>
          </xsl:for-each>
        </UL>
      </xsl:template>  <xsl:template match="emph">
        <I><xsl:apply-templates /></I>
      </xsl:template>    <xsl:template match="text()"><xsl:value-of /></xsl:template>
      
    </xsl:stylesheet>
    xml如下:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="pole.xsl"?>
    <document>
      <title>To the Pole and Back</title>
      <section>
        <title>The First Day</title>
        <p>It was the <emph>best</emph> of days, it was the
          <emph>worst</emph> of days.</p>
        <list>
          <item><emph>best</emph> in that the sun was out.</item>
          <item><emph>worst</emph> in that it was 39 degrees below zero.</item>
        </list>
        <section>
          <title>Lunch Menu</title>
          <list>
            <item>ice cream</item>
            <item>popsicles</item>
          </list>
        </section>  </section>  <section>
        <title>The Second Day</title>
        <p>Ditto the first day.</p>
      </section></document>
    楼上的兄弟可以试试
      

  7.   

    楼上的朋友,你到底问的是什么问题?是通过xslt转换xml到ie呢?还是通过程序调用xml和xslt结合?