I have a XSL script that has this towards the top:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<xsl:choose>
<xsl:when test="$CSSFile1 !=''">
<style type="text/css">
<xsl:value-of select="$CSSFile1"/>
</style>
</xsl:when>
<xsl:otherwise>
<link rel="stylesheet" type="text/css" href="Workbook-S-140-PublicTalk-WatchtowerStudy-ServiceTalk-Videoconference2.css"/>
<link rel="stylesheet" type="text/css" href="Workbook-S-140-PublicTalk-WatchtowerStudy-ServiceTalk-Zoom.css"/>
</xsl:otherwise>
</xsl:choose>
<title>
<xsl:value-of select="//Labels/Congregation"/> <xsl:value-of select="//Labels/Title" />
</title>
</head>
As you can see, when $CSSFile1
is empty it should include two style sheets.
The above is part of a XSL / XML transformation that is used in a CHtmlView
control in my MFC project and in itself it works fine.
But ...
I have a feature that allows the user to export the same data to a HTML file and it is support to do this using a C# DLL that I wrote which does it's own transformation using the same data. The code:
public bool TransformXMLToHTML(string strTransformXSLPath, string strScheduleXMLPath, string strScheduleHTMLPath)
{
try
{
var xmlResolver = new XmlUrlResolver();
XsltArgumentList argsList = new XsltArgumentList();
string strRootPath = Path.GetDirectoryName(strTransformXSLPath);
// Read the XSL file and locate all the CSS documents that are used
int iFileCount = 0;
string[] lines = File.ReadAllLines(strTransformXSLPath);
foreach (string line in lines)
{
if ((line).Trim().Contains("text/css"))
{
int iHREFIndex = line.IndexOf("href=\"");
if (iHREFIndex != -1)
{
string strCSSFile = line.Substring(iHREFIndex + 6);
int iQuoteIndex = strCSSFile.IndexOf("\"");
if (iQuoteIndex != -1)
{
strCSSFile = strCSSFile.Substring(0, iQuoteIndex);
// Build full path and make sure the file exists
string strCSSFilePath = Path.Combine(strRootPath, strCSSFile);
if(File.Exists(strCSSFilePath))
{
// Establish the parameter name
iFileCount++;
string strParamName = "CSSFile" + iFileCount.ToString();
// Read the content and attach
string strCSSFileContent = File.ReadAllText(strCSSFilePath);
argsList.AddParam(strParamName, "", strCSSFileContent);
}
}
}
}
}
// Now perform the transformation
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(strTransformXSLPath, new XsltSettings { EnableDocumentFunction = true }, xmlResolver);
using (StreamWriter sw = new StreamWriter(strScheduleHTMLPath))
{
transformer.Transform(strScheduleXMLPath, argsList, sw);
}
}
catch (Exception ex)
{
SimpleLog.Log(ex);
return false;
}
return true;
}
Something is going wrong because the transformation is supposed to embed both CSS files and it only ends up embedded the first one. There are no errors raised.