这是我的xslt:
username
它呈现在html文档的头部。问题是它没有渲染到页面上。我认为这与在<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<html>
<xsl:call-template name="header">
<xsl:with-param name="title">Strip Club List - Top 100
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
Highest Number of Comments
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
Highest Number of Reviews
</xsl:when>
<xsl:when test="/*/general/viewmethod='highestreviews'">
Highest Rating
</xsl:when>
<xsl:when test="/*/general/viewmethod='numlikes'">
Highest Number of Likes
</xsl:when>
<xsl:when test="/*/general/viewmethod='numdislikes'">
Highest Number of Dislikes
</xsl:when>
<xsl:when test="/*/general/viewmethod='numfollowers'">
Highest Number of Followers
</xsl:when>
</xsl:choose>
<xsl:value-of select="/*/locations/name" /></xsl:with-param>
<xsl:with-param name="stylesheets">fonts.css,core.css,state.css,top.css</xsl:with-param>
<xsl:with-param name="scripts">core.js,state.js</xsl:with-param>
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
</xsl:choose>
</xsl:call-template>
<body>
<div id="body"></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
中使用style tags
有关。
XML:
XSLT document
我也试过了:
<root>
<general>
<viewmethod>numreviews</viewmethod>
</general>
</root>
这是我的<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='highestreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numlikes'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numdislikes'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numfollowers'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
</xsl:choose>
header template
感谢
答案 0 :(得分:0)
正如评论中所提及的,xsl:choose
不能是xsl:call-template
的孩子。有关语法,请参阅http://www.w3.org/TR/xslt#named-templates。在这种情况下,您使用的XSLT处理器可能只是忽略xsl:choose
,而不是抛出错误。
您可能需要做的是在style
模板中添加header
参数,然后使用xsl:with-param
以与其他参数类似的方式传递样式。< / p>
尝试将此XSLT作为一个简洁的示例:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<html>
<xsl:call-template name="header">
<xsl:with-param name="title">Test</xsl:with-param>
<xsl:with-param name="keywords" select="/root/general/viewmethod" />
<xsl:with-param name="style">
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<body>
<div id="body"></div>
</body>
</html>
</xsl:template>
<xsl:template name="header">
<xsl:param name="title" />
<xsl:param name="keywords" />
<xsl:param name="style" />
<head>
<xsl:if test="string-length($keywords) > 0"><meta name="keywords" content="{$keywords}" /></xsl:if>
<xsl:copy-of select="$style" />
<title><xsl:value-of select="$title" /></title>
</head>
</xsl:template>
</xsl:stylesheet>