Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
名称中的CSS空格&麻烦的XSLT_Css_Xslt_Xpath - Fatal编程技术网

名称中的CSS空格&麻烦的XSLT

名称中的CSS空格&麻烦的XSLT,css,xslt,xpath,Css,Xslt,Xpath,我正在尝试创建一个XSLT,它列出电影,并对标题进行样式化,使每个标题都有自己的颜色,然后使用XPath选择标题 以下是XSL文件: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html>

我正在尝试创建一个XSLT,它列出电影,并对标题进行样式化,使每个标题都有自己的颜色,然后使用XPath选择标题

以下是XSL文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <html>
        <head>
            <title>Videos</title>
            <style>
                table, tr, td { border: thin black solid }
                th { background-color: #AAFFAA }
                .Daredevil { color: red; }

                /* Look at those spaces! Hrmphf! */
                .Drag Me To Hell { color: green; }
            </style>
        </head>
        <body>
            <table>
                <tr><th>Movies</th></tr>
                <xsl:apply-templates select="//movie"/>
            </table>
        </body>
    </html>
</xsl:template>
<xsl:template match="//movie[not(@title=preceding::movie/@title)]">

    <!-- Title should be the one of the titles in the CSS -->
    <tr class="{@title}"><td><xsl:value-of select="@title"/></td></tr>

</xsl:template>
</xsl:stylesheet>
然而,问题是一些电影标题包含空格。我可以在名字中加空格吗?如果没有,除了在XML中添加下划线或类似内容之外,还有什么变通方法吗

更新:


好吧,我明白这是不可能的。目前我正在使用translate@title“,”,“-”在CSS名称以-分隔时起作用。我仍然想知道是否有更好的方法

否,CSS规则名称中不能有空格

class=拖动我以创建包含三个不同类的元素

selector.Drag.Me.To将匹配所有三个类的元素


但是,它将以任何顺序匹配它们,并且不会计算重复项。

CSS类/id不能包含空格

因为一个空格用来分隔不同的类


您将不得不解析为-

我觉得用这种方式将CSS与实际数据内容联系起来有点奇怪。您的样式表似乎提前知道它希望在数据文件中找到什么,这感觉像是糟糕的设计——它应该是通用的。为什么不引入从电影标题到CSS类的间接寻址:

<xsl:variable name="movieStyles">
  <movie title="Drag me to hell" css-class="hell-class"/>
  <movie ...
</xsl:variable>

那么这是一个非常好的观点我一直在玩弄XSLT,想让它成为动态的,但实际上它是硬编码的。我现在计划制作一个小应用程序,根据XML中的标题创建CSS文件,这样算法将确定标题的颜色。是的,你可以说我疯了