css在xsl文档中

inp*_*put 14 css xslt

我如何在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" />
Run Code Online (Sandbox Code Playgroud)

但它抛出了错误:

XSLTProcessor::importStylesheet(): Found a top-level element link with null namespace URI 
Run Code Online (Sandbox Code Playgroud)

Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object 
Run Code Online (Sandbox Code Playgroud)

Jas*_*ams 5

您的 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>
Run Code Online (Sandbox Code Playgroud)

  • 那么问题是关于将 xml 转换为 html 是一件好事。 (8认同)

Rob*_*Rob 1

“link”是一个 HTML 元素,而您正尝试将其用作 XML 元素。XSL 将输入修改到另一个文档中。您不在 XSL 文件中使用 CSS。您将其插入 (X)HTML 文件并在那里应用。