xslt中的样式标记无法呈现

时间:2015-11-05 17:07:53

标签: css xml xslt

这是我的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'"> &lt;style&gt; .linked_location .rating { right: 100px; } &lt;/style&gt; </xsl:when> <xsl:when test="/*/general/viewmethod='highestreviews'"> &lt;style&gt; .linked_location .rating { right: 100px; } &lt;/style&gt; </xsl:when> <xsl:when test="/*/general/viewmethod='numlikes'"> &lt;style&gt; .linked_location .rating { right: 90px; } &lt;/style&gt; </xsl:when> <xsl:when test="/*/general/viewmethod='numdislikes'"> &lt;style&gt; .linked_location .rating { right: 90px; } &lt;/style&gt; </xsl:when> <xsl:when test="/*/general/viewmethod='numfollowers'"> &lt;style&gt; .linked_location .rating { right: 90px; } &lt;/style&gt; </xsl:when> </xsl:choose>

header template

感谢

1 个答案:

答案 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) &gt; 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>