output method="html" : output « XSLT stylesheet « XML






output method="html"


File: Data.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Books.xsl"?>
<Books xmlns="http://www.java2s.com"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Book xmlns="http://www.java2s.com">
                <Title>title 1</Title>
                <Author>author 1</Author>
                <Date>1998</Date>
                <ISBN>1-11111-111-1</ISBN>
                <Publisher>publisher 1</Publisher>
        </Book>
        <Book xmlns="http://www.java2s.com">
                <Title>title 2</Title>
                <Author>author 2</Author>
                <Date>1977</Date>
                <ISBN>2-222-22222-2</ISBN>
                <Publisher>publisher 2</Publisher>
        </Book>
</Books>


File: Books.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xlink="http://www.w3.org/1999/xlink/namespace"
                xmlns:bks="http://www.java2s.com"
                xmlns:bk="http://www.java2s.com"
                exclude-result-prefixes="bk bks"
                version="1.0">
 
    <xsl:output method="html"/>

    <xsl:include href="Book.xsl"/>

    <xsl:template match="/">
        <HTML>
            <BODY>
                <xsl:apply-templates/>
            </BODY>
        </HTML>
    </xsl:template>

    <xsl:template match="bks:Books">
         <CENTER><H2>My Bookstore</H2></CENTER>
         <TABLE border="1">
             <xsl:apply-templates/>
         </TABLE>
    </xsl:template>

    <xsl:template match="bks:Book">
         <xsl:variable name="book-url" select="document(@xlink:href)"/>
         <xsl:apply-templates select="$book-url//bk:Book"/>
    </xsl:template>

</xsl:stylesheet>


File: Book.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:bk="http://www.java2s.com"
                exclude-result-prefixes="bk"
                version="1.0">
 
    <xsl:output method="html"/>

    <xsl:template match="/">
        <HTML>
            <BODY>
                <TABLE border="1">
                    <xsl:apply-templates/>
                </TABLE>
            </BODY>
        </HTML>
    </xsl:template>

    <xsl:template match="bk:Book">
         <TR>
             <xsl:apply-templates/>
         </TR>
    </xsl:template>

    <xsl:template match="*">
         <TD>
             <xsl:value-of select="."/>
         </TD>
    </xsl:template>

</xsl:stylesheet>

 








Related examples in the same category

1.format output with tab
2.output rtf in format
3.Add , to the output
4.Output text with tag
5.Add your signs to the output (output method="text")
6.Output text with xsl:text
7.output method="xml" omit-xml-declaration="yes" indent="no"
8.Output html option list
9.Output HTML tags
10.Select with value-of and output with new tags