xsl 文档中的 css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3378297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
css in xsl document
提问by input
how do i implement css in xsl file? i tried this:
我如何在 xsl 文件中实现 css?我试过这个:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
<xsl:output method="html" />
but it threw the error:
但它抛出了错误:
XSLTProcessor::importStylesheet(): Found a top-level element link with null namespace URI
and
和
Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object
回答by Jason Williams
Your html (link tag) must be inside an xsl:template. The xsl:template must be inside an xsl:stylesheet.
您的 html(链接标签)必须位于 xsl:template 内。xsl:template 必须在 xsl:stylesheet 内。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/*//*[1]">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
</xsl:template>
</xsl:stylesheet>
回答by cm2
If I understand you correctly, you wish for the output to have a particular stylesheet?
如果我理解正确,您希望输出具有特定的样式表吗?
XSL is a language used to transform XML from one format to another (in a sense it's like applying a css stylesheet). What would happen in a typical use case is that you would take some xml file and use XSL to transform it, say to XHTML. In this output, you can include a stylesheet using the link element if you wanted, but XSL doesnt really make use of CSS as such. (So basically, try putting the CSS in the XSL as part of the transformation to have the XHTML output use it.)
XSL 是一种用于将 XML 从一种格式转换为另一种格式的语言(从某种意义上说,它就像应用 css 样式表)。在典型用例中会发生的情况是,您将获取一些 xml 文件并使用 XSL 对其进行转换,比如 XHTML。在此输出中,您可以根据需要使用链接元素包含样式表,但 XSL 并没有真正使用 CSS。(所以基本上,尝试将 CSS 放在 XSL 中作为转换的一部分,让 XHTML 输出使用它。)
If this is an XML document you simply need to include the reference to the XSL and it should handle the transformation for you automatically.
如果这是一个 XML 文档,您只需要包含对 XSL 的引用,它就会自动为您处理转换。
回答by Rob
'link' is a HTML element and you're trying to use it as an XML one. XSL modifies input into another document. You don't use CSS in an XSL file. You insert it into an (X)HTML file and apply it there.
'link' 是一个 HTML 元素,您正试图将其用作 XML 元素。XSL 将输入修改为另一个文档。您不在 XSL 文件中使用 CSS。您将其插入到 (X)HTML 文件中并在那里应用。