Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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/7/css/36.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
Html 在外部css样式表中使用XSLT变量_Html_Css_Xml_Xslt - Fatal编程技术网

Html 在外部css样式表中使用XSLT变量

Html 在外部css样式表中使用XSLT变量,html,css,xml,xslt,Html,Css,Xml,Xslt,我有一个名为general.xsl的文件,其中包含 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0"> <xsl:variable name="p-size" select="'20'" &

我有一个名为
general.xsl
的文件,其中包含

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0">

<xsl:variable name="p-size" select="'20'" ></xsl:variable>
<xsl:variable name="main-title-size" select="'36'" ></xsl:variable>
<xsl:variable name="list-item-size" select="'22'" ></xsl:variable>

</xsl:stylesheet>
现在,在我的
ppt.css
中,我想使用
general.xsl
文件中的变量
font-color
p-size
(比如说在general.xsl中,我已经定义了所有需要的变量),但它不是这样工作的:

p{
    color:{$font-color};
    font-size:{$p-size}px;
}

需要更改什么?

如果你想在CSS文件中使用变量,你应该看看CSS预处理器

使用这种工具,您可以维护“动态CSS模板”,并从中生成静态CSS文件


然后,您可以简单地将静态样式名称分配给XSL代码中的元素

不能在外部样式表中使用xslt变量。XSLT根本不处理这个css文件。它只是在html文档中输出一个
链接
标记,浏览器将对其进行处理。当浏览器处理它时,XSLT过程将早已结束。@TimC那么我只能使用内联css吗?是的,如果您在
标记中生成内联css,您可以使用XSLT变量。当您使用XSLT 2时(至少
version=“2.0”
表明这一点)您还可以使用XSLT代码生成CSS文件作为辅助结果文档,例如,
p{color:}
p{
    color:{$font-color};
    font-size:{$p-size}px;
}