Illegal Characters in Path for XSLT Tranformation

2019-10-04 12:59发布

This question already has an answer here:

I am writing an XSLT transformation to translate a XML credit report.

When I run the following code I am getting "Illegal Characters in Path" error. Not sure what I am missing. I want this method to return a HTML string.

I have tested the XSLT transform on the XML and it works. This code fails on the transform.Load function with the "Illegal Characters in Path" error.

What am I missing here?

    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:

<xsl:template match="/">

  <html>
    <body>

      <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>


  </body>
</html>

</xsl:template>

标签: c# xml xslt
1条回答
我想做一个坏孩纸
2楼-- · 2019-10-04 13:39

I was bad and posted this question a second time, but someone was able to give me an answer so here it is....

    var xsltTemplate = File.ReadAllText(path);
    xsltTransform.Load(xsltTemplate);

should have been

    xsltTransform.Load(path);

and all is perfect.

查看更多
登录 后发表回答