日期:2014-05-17  浏览次数:20815 次

xslt转html2
(转)java使用XSL+XML生成HTML文件2009-10-27 19:56转:http://www.blogjava.net/yangxiang/archive/2009/08/11/290688.html

1、xml.xml
<?xml version="1.0" encoding="utf-8"?>
<book>
    <title>XML与JSP</title>
    <chapter>
        <title>第1章 认识XML与DTD</title>
        <section>
            <title>XML的产生</title>
            <example>HelloWorld.html</example>
        </section>
    </chapter>
    <chapter>
        <title>第2章 XML名称空间</title>
        <section>
            <title>名称空间在元素和属性中的应用</title>
            <section>
                <title>名称空间在元素中的应用</title>
                <example>people.xml</example>
            </section>
            <section>
                <title>缺省名称空间</title>
                <example>book.xml</example>
            </section>
            <section>
                <title>名称空间在属性中的应用</title>
                <example>book2.xml</example>
            </section>
        </section>
        <section>
            <title>名称空间和DTD</title>
        </section>
    </chapter>
</book>

2、xsl.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="utf-8" standalone="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>使用XML+XSLT生成的HTML文件</title>
            </head>
            <body>
                <xsl:apply-templates select="book"/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="chapter">
    &nb