简体   繁体   English

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

[英]Use XSLT variable in external css stylesheet

I have a file called general.xsl which contains 我有一个名为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>

Then I have html.xsl file, which includex my external ppt.css file and also contains for example paragraph template: 然后,我有了html.xsl文件,其中包括我的外部ppt.css文件,并且还包含例如段落模板:

<link rel="stylesheet" type="text/css" href="ppt.css"/>
.. some code...
<xsl:template name="p" match="p">
    <p>
        <xsl:value-of select="current()"/>
    </p>
</xsl:template>

Now, in my ppt.css I want to use variables font-color or p-size from general.xsl file (lets say in general.xsl, I have defined all variables needed), but it doesn't work this way: 现在,在我的ppt.css我想使用general.xsl文件中的变量font-colorp-size (让我说在general.xsl中,我已经定义了所有需要的变量),但是这种方式无法正常工作:

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

What needs to be changed? 需要更改什么?

If you want to use variables in CSS files you should take a look at CSS preprocessors like Sass . 如果要在CSS文件中使用变量,则应查看Sass之类的CSS预处理器

With this kind of tools you can maintain "dynamic CSS templates" and generate static CSS files out of it. 使用这种工具,您可以维护“动态CSS模板”并从中生成静态CSS文件。

Then you can simply assign static style-names to elements in your XSL code. 然后,您可以简单地为XSL代码中的元素分配静态样式名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM