我使用此代码从XML文档加载XSL(XSL具有嵌入数据):
public void SetHtmlSourceFromXmlDocument(XmlDocument xmlDocument)
{
var transform = new XslCompiledTransform();
transform.Load(xmlDocument);
// ...
}
在客户计算机上transform.Load(xmlDocument)
第一次需要15秒。后续调用大约需要1毫秒。软件重启:第一次通话需要15秒。
这只发生在我们的服务器构建中,来自我的计算机的构建(也是发布)将运行得很好(我知道服务器构建标记程序集的唯一事情)。 此问题也只发生在非开发人员系统上(没有Visual Studio,没有Internet访问,只有Intranet)。在其中一个有问题的系统中,这个问题消失了,但我不明白为什么(看起来我做了一些事情,我不知道什么,不能再在这个系统上再现错误)。
我也尝试transform.Load(xmlDocument, null, null)
或提供我自己的XmlResolver
(GetEntity
从未被调用过),因为我读到XslCompiledTransform
可能会尝试访问xmlns名称空间网址来验证文件(也许我误解了)。
我无法在这些计算机上安装Visual Studio进行调试。 有人知道可能导致这个问题的原因或者我可以尝试找到问题吗?
Xml文件:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" encoding="utf-8" href="#"?>
<xsl:stylesheet version="1.0" xmlns:data="http://zeiss.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<data:data>
<calibrationLog>
<name>DetectorOffsetCalibration</name>
<entry timestamp="2015-03-25T18:49:24.0313832+01:00" userGroup="Customer" level="Info" indent="0" message="Created at Wednesday, 25 March 2015 18:49:24 (+01 UTC) by Developer on ZEISS-PC." />
</calibrationLog>
</data:data>
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates select="data:data" />
</xsl:template>
<xsl:template match="calibrationLog">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>
<xsl:value-of select="name" />
</title>
<style type="text/css">
html, body, p { margin: 0; padding: 0; font-family: Arial; font-size: 12pt; background-color: #FFFFFF;; }
p { white-space: pre-wrap; }
</style>
</head>
<body>
<h3 style="margin: 0.2em 1em;">Calibration Log "<xsl:value-of select="name" />"</h3>
<xsl:for-each select="entry">
<xsl:variable name="style">
<xsl:choose>
<xsl:when test="@level = 'Debug'">display: none</xsl:when>
<xsl:when test="@level = 'Info'">color: Black; background-color: White</xsl:when>
<xsl:when test="@level = 'IntermediateResult'">color: Black; background-color: CornflowerBlue</xsl:when>
<xsl:when test="@level = 'Result'">color: Black; background-color: YellowGreen</xsl:when>
<xsl:when test="@level = 'SilentWarning'">color: Black; background-color: Yellow</xsl:when>
<xsl:when test="@level = 'Warn'">color: Black; background-color: Yellow</xsl:when>
<xsl:when test="@level = 'Error'">color: White; background-color: OrangeRed</xsl:when>
<xsl:when test="@level = 'Device'">color: Lightgray; background-color: White</xsl:when>
<xsl:when test="@level = 'Section'">color: Darkmagenta; background-color: White; font-weight: Bold; border-color: darkmagenta; border-width: 10; border-top-style: Double; border-bottom-style: Double; margin: 0.5em 0; padding-top: 0.3em; padding-bottom: 0.3em</xsl:when>
<xsl:when test="@level = 'SubSection'">color: Darkmagenta; background-color: White; font-weight: Bold;</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="currentIndent" select="1.25 + @indent" />
<p style="{$style}; padding-left: {$currentIndent}em; text-indent: -1em;">
<xsl:value-of select="@message" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>