使用xsl 3.0

时间:2017-02-02 20:01:00

标签: html xml xslt

我在使用转换页面的XSL样式表选择XML文档中的HTML表时遇到问题。

我正在尝试使用class =“table factbook”选择表。 XML看起来像:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> ]>
<document>

    <headcode></headcode> <!-- before closing head tag -->
    <bodycode></bodycode> <!-- after opening body tag -->
    <footcode></footcode> <!-- before closing body tag -->


        <h4>University of Georgia Fact Books</h4>
        <table class="table factbook">
            <caption>Table becomes a bunch of divs</caption>
            <tbody>
                <tr>
                    <td>
                        <h3>2016</h3>
                        <a href="/_resources/files/factbook/FactBook2016.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2016FB_Cover_thumb.jpg" alt="" /></a></td>
                    <td>
                        <h3>2015</h3>
                        <a href="/_resources/files/factbook/FactBook2015.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2015FB-Cover_thumb.png" alt="" /></a></td>
                    <td>
                        <h3>2014</h3>
                        <a href="/_resources/files/factbook/FactBook2014.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2014FB-Cover_thumb.png" alt="" /></a></td>
                    <td>
                        <h3>2013</h3>
                        <a href="/_resources/files/factbook/FactBook2013.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="http://69.39.227.24/_resources/files/factbook/2013FB-Cover_thumb.png" alt="" /></a></td>
                </tr>
            </tbody>
        </table>
</document>

XSL看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:output method="html" indent="yes" encoding="UTF-8" include-content-type="no" />

    <xsl:strip-space elements="*"/>

    <!-- factbook transformation -->
    <xsl:template match="//table[@class='table factbook']">
        <xsl:for-each select="tbody/tr/td">
            <div class="grid">
                <xsl:copy-of select="node()"/>
            </div>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="/document">
        <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML></xsl:text>
        <html lang="en">
            <head>
                <xsl:apply-templates select="headcode/node()"/>
            </head>
            <body>          
                <xsl:apply-templates select="bodycode/node()"/>
                <div class="wrap" role="document">
                    <div class="content">
                        <div class="container">
                            <xsl:call-template name="page-content"/>
                        </div>
                    </div>
                </div>
                <xsl:apply-templates select="footcode/node()"/> <!-- pcf -->    
            </body>
        </html> 
    </xsl:template>

    <xsl:template name="page-content">
        <xsl:copy-of select="/document">
    </xsl:template>

</xsl:stylesheet>

0 个答案:

没有答案