Illegal Characters in Path when loading XSLT docum

2020-05-09 22:18发布

I am creating a method to return an HTML string as the result of an XSLT transformation.

When I run the following code I am getting Illegal Characters in Path error on the following line: xsltTransform.Load(xsltTemplate).

Note I have tested the XSLT transform via another method and it works.

private string FormatCreditReport(string inputXml)
{
    var xsltTransform = new XslCompiledTransform();
    var webRootPath = HostingEnvironment.ApplicationPhysicalPath;
    var path = webRootPath
               + "XSLT_Stylesheets"
               + Path.DirectorySeparatorChar
               + "CreditReportTransform.xslt";
    var xsltTemplate = File.ReadAllText(path);

    xsltTransform.Load(xsltTemplate);

    StringWriter results = new StringWriter();
    using (var reader = XmlReader.Create(new StringReader(inputXml)))
    {
        xsltTransform.Transform(reader, null, results);
    }
    return results.ToString();
}

XSLT Document:

  <table border ="1">

    <tr>
      <th><h2>Credit File</h2></th>
    </tr>
    <tr></tr>
    <tr>
      <td>File Since Date</td>
      <td><xsl:value-of select="EfxTransmit/EfxReport/USConsumerCreditReports/USConsumerCreditReport/USHeader/CreditFile/FileSinceDate"/></td>
    </tr>
    <tr>
      <td>Date of Last Activity</td>
      <td><xsl:value-of select="EfxTransmit/EfxReport/USConsumerCreditReports/USConsumerCreditReport/USHeader/CreditFile/DateOfLastActivity"/></td>
    </tr>
    <tr>
      <td>Date of Request</td>
      <td><xsl:value-of select="EfxTransmit/EfxReport/USConsumerCreditReports/USConsumerCreditReport/USHeader/CreditFile/DateOfRequest"/></td>
    </tr>

    <tr></tr>

    <tr>
      <th><h2>Subject</h2></th>
    </tr>
    <tr>
      <td>Last Name</td>
      <td><xsl:value-of select="EfxTransmit/EfxReport/USConsumerCreditReports/USConsumerCreditReport/USHeader/Subject/LastName"/></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </table>

标签: xml xslt
1条回答
做自己的国王
2楼-- · 2020-05-09 23:13

There is no need to call File.ReadAllText(path). Just pass the fully qualified file path as follows:

'var xsltTemplate = File.ReadAllText(path);
xsltTransform.Load(path);
查看更多
登录 后发表回答