XSLT - 为什么3个不同的“选择值”与3个不同的xpath的结果给出了同一行的输出?

时间:2017-01-21 17:33:16

标签: xslt xhtml

所以我有这个.xsl文件和3个不同的“xsl:value-of select”和不同的xpath让我在同一行,即使是断行试图将它们分开。

xsl代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />


    <xsl:template match="/">
        <html>
            <head>
                <title></title>
            </head>
            <body>
                <xsl:value-of select="//Utilizador[@id= 'u_03' ]/Username"/><br/>

                <xsl:value-of select="count(//Video[contains(@uti_id, 'u_03')])"/><br/>

                <xsl:value-of select="count(//Comentario[contains(@uti_id, 'u_03')])"/><br/>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

和输出.xhtml:

<?xml version="1.0" encoding="UTF-8"?><html>
<head>
<title/>
</head>
<body>carlitos<br/>3<br/>0<br/>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

确保使用<xsl:output method="html"/>创建text / html输出。如果你想创建XHTML,那么你可以使用output method =&#34; xml&#34;,但是你还需要XHTML命名空间http://www.w3.org/1999/xhtml作为结果元素,否则浏览器将无法识别任何HTML。