简体   繁体   English

如何在XSL中嵌入C#代码生成的HTML?

[英]How to embed HTML produced by C# code in XSL?

I have XSLT that creates HTML from XML. 我有从XML创建HTML的XSLT。 There are several parts of the resulting HTML that I need to create by external C# method (extension method). 我需要通过外部C#方法(扩展方法)创建HTML的结果。

  1. How do I embed this C# method into XSLT (within what xsl nodes? I do know how to use common extension functions inside XSLT) 我如何将此C#方法嵌入XSLT(在xsl节点内?我知道如何在XSLT内部使用通用扩展功能)
  2. What should my C# function return? 我的C#函数应该返回什么? HTML-formatted string? HTML格式的字符串? With escaped HTML tags or without? 有转义的HTML标签还是没有?

Thank you very much! 非常感谢你!

Well if you want to return HTML tag soup not conforming to XML rules then you can only return a string and then use eg <xsl:value-of select="pf:yourFunction()" disable-output-escaping="yes"/> . 好吧,如果您想返回不符合XML规则的HTML标签,那么您只能返回一个字符串,然后使用例如<xsl:value-of select="pf:yourFunction()" disable-output-escaping="yes"/> If you want to build a node-set of nodes or a result tree fragment then check the documentation , it shows the mapping between the XSLT types and the .NET framework types eg if you want your function to return an result that XSLT sees as a node-set then use the type XPathNodeIterator as the .NET return type of your extension function. 如果要构建节点的节点集或结果树片段,请查看文档该文档显示了XSLT类型和.NET Framework类型之间的映射,例如,如果您希望函数返回XSLT视为节点集,然后使用XPathNodeIterator类型作为扩展功能的.NET返回类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM