XSL样式表无法编译

时间:2013-11-19 13:13:51

标签: xml xslt

我目前正在尝试学习XML,当我尝试使用样式表将我的XML文件转换为html文件时,我只是被告知它“无法编译样式表”。我不知道样式表中是否有错误或问题是什么。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
        <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:template match="invoices">
        <html>
            <head>
                <title>acmeTransform</title>
                <style type = "text/css"></style>
            </head><body>
            <h1>Invoices</h1>
            <table>
            <tr bgcolor = "light blue">
                <th align="center">Code</th>
                <th align="center">Date</th>
                <th align="center">Customer Name</th>
                <th align="center">Description</th>
                <th align="center">Value</th>
                <th align="center">Status</th>
            </tr>
            <xsl:apply-templates select = "//invoice" />
            </table>
            </body>
         </html>
    </xsl:template>
    <xsl:template match = "invoice">
        <tr bgcolor = "light blue">
        <td align="center">Code<xsl:value-of select = "invoice-code"/></td>
        <td align="center">Date<xsl:value-of select = "date"/></td>
        <td align="center">Customer Name<xsl:value-of select = "customer-first-name/customer-surname"/></td>
        <td align="center">Description<xsl:value-of select = "description"/></td>
        <td align="center">Value<xsl:value-of select = "value"/></td>
        <td align="center">Status<xsl:value-of select = "status"/></td>
        </tr>
    </xsl:template>

</xsl:stylesheet>

<xsl:value-of select="title"/>  

3 个答案:

答案 0 :(得分:1)

您缺少xsl:stylesheet结束标记。尝试将其添加到最后:

</xsl:stylesheet>

答案 1 :(得分:0)

在关闭<xsl:value-of select="title"/>标记后,您有一个悬空</xsl:stylesheet>,您需要将其删除以使XML格式正确。除此之外,你的样式表的其余部分对我来说很好。

答案 2 :(得分:0)

更好的方法是将<xsl:value-of select="title" />添加到模板,然后关闭</xsl:stylesheet>,因为 Ian Roberts 表示其格式不正确,因为<xsl:value-of select="title" />不是在适当的地方。