【发布时间】:2021-01-31 10:34:26
【问题描述】:
我需要对多个 XML 文件进行转换。为了进行转换,我有一个包含各种 xsl 样式表的文件夹。我需要使用 Java 解析器进行转换,并且我不控制任何样式表的内容。
样式表通过xsl:import 语句相互引用,它们还包含如下css样式:
<style type="text/css">
<xsl:value-of select="document('../../common/display.css')" disable-output-escaping="yes"/>
</style>
简化示例
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../../common/functions.xsl"/>
<xsl:template match="/">
<html>
<head>
<title>..</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style type="text/css">
<xsl:value-of select="document('../../common/display.css')" disable-output-escaping="yes"/>
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
通过使用以下样式表进行首次处理,我设法包含了所有其他 xsl 文件。
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="xsl:include">
<xsl:copy-of select="document(@href)/xsl:stylesheet/*"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
但是我不知道如何对 css 引用做同样的事情。是否甚至可以评估 xsl:value-of 以获取对 document() 的调用中的字符串的值,或者获取外部 css 文件的内容?
【问题讨论】: