Visual C#显示XML Web浏览器
因此,我遵循的教程。我有以下代码,但它在web浏览器组件中不会显示任何内容。我遵循的具体说明如下: “大家好 我使用以下策略成功地做到了这一点:Visual C#显示XML Web浏览器,c#,xml,visual-studio-2010,xslt,C#,Xml,Visual Studio 2010,Xslt,因此,我遵循的教程。我有以下代码,但它在web浏览器组件中不会显示任何内容。我遵循的具体说明如下: “大家好 我使用以下策略成功地做到了这一点: 下载兼容HTML1.0的defaultss.xsl版本(我正在使用自己的) 创建一个XMLCompiledTransform对象并加载“defaultss.xsl”样式表。实际上,我将它作为一个资源嵌入到我的程序集中,并从那里读取它 使用XMLCompiledTransform将XML流转换为HTML流 设置WebBrowser.DocumentStr
<?xml version="1.0" encoding="UTF-8"?>
<CDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://xreg2.nist.gov:8080/hitspValidation/schema/cdar2c32/infrastructure/cda/C32_CDA.xsd" xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif">
<realmCode code="US"/>
<typeId root="2.16.840" extension="PO"/>
<templateId root="2.16"/>
<templateId root="2.17"/>
<id root="2.16.84" extension="E5"/>
<code codeSystem="2.16.88" codeSystemName="" code="3" displayName="TITLE"/>
<title>TITLE</title>
<effectiveTime value="2925"/>
<confidentialityCode code="Y" codeSystem=""/>
<recordTarget>
<patientRole>
<id root="2.16.84" extension="215"/>
<addr use="P">
<streetAddressLine>123 GREEN TRAIL RD</streetAddressLine>
<city>BIRMINGHAM</city>
<state>AL</state>
<postalCode>35211</postalCode>
<country>USA</country>
</addr>
<telecom use="H" value="tel:000000000"/>
<patient>
<name>
<given qualifier="L">ADAM</given>
<family qualifier="R">EVERYMAN</family>
</name>
<ethnicGroupCode codeSystem="2.16.84" codeSystemName="Race" displayName="Not Hispanic or Latino"/>
<languageCommunication>
<languageCode code="eng"/>
</languageCommunication>
</patient>
</patientRole>
</recordTarget>
XSL is also long so here is a piece of it:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n3="http://www.w3.org/1999/xhtml" xmlns:n1="urn:hl7-org:v3" xmlns:n2="urn:hl7-org:v3/meta/voc" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html" indent="yes" version="4.01" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
<xsl:variable name="tableWidth">50%</xsl:variable>
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="/n1:CDocument/n1:title">
<xsl:value-of select="/n1:CDocument/n1:title"/>
</xsl:when>
<xsl:otherwise>CDocument</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="n1:CDocument"/>
</xsl:template>
我找到的解决方案是使用以下代码。此代码将保存result.html并在web浏览器控件内呈现该结果
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(xslpath);
string directoryPath = Path.GetDirectoryName(filepath);
myXslTrans.Transform(filepath, directoryPath+"result.html");
webBrowser1.Navigate(directoryPath+"result.html");
您是否验证了XSL转换在该代码之外工作?请共享您的源XML和样式表。是的,我已经验证了它是否在这段代码之外工作。我已经更新了我的问题,以包含您提到的资源。
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(xslpath);
string directoryPath = Path.GetDirectoryName(filepath);
myXslTrans.Transform(filepath, directoryPath+"result.html");
webBrowser1.Navigate(directoryPath+"result.html");