小编pet*_*ter的帖子

.net 4 xslt扩展对象

我正在升级asp.net v3.5网络应用程序.到v4,我在XmlDataSource对象上使用的XSLT转换遇到了一些问题.

XSLT文件的一部分:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ExtensionObject="ds:ExtensionObject"> 
  <xsl:output method="xml" indent="yes" encoding="utf-8"/> 
  <xsl:template match="/Menus"> 
    <MenuItems> 
      <xsl:call-template name="MenuListing" /> 
    </MenuItems> 
  </xsl:template> 

  <xsl:template name="MenuListing"> 
    <xsl:apply-templates select="Menu" /> 
  </xsl:template> 

  <xsl:template match="Menu"> 
      <MenuItem> 
        <xsl:attribute name="Text"> 
          <xsl:value-of select="ExtensionObject:HtmlEncode(MenuTitle)"/> 
        </xsl:attribute> 
        <xsl:attribute name="ToolTip"> 
          <xsl:value-of select="MenuTitle"/> 
        </xsl:attribute> 
      </MenuItem> 
  </xsl:template> 
</xsl:stylesheet> 
Run Code Online (Sandbox Code Playgroud)

这是初始化:

xmlDataSource.TransformArgumentList.AddExtensionObject("ds:ExtensionObject", new ExtensionObject()); 
xmlDataSource.Data = Cache.FetchPageMenu(); 
Run Code Online (Sandbox Code Playgroud)

ExtensionObject:

public class ExtensionObject {
    public static string HtmlEncode(string input) {
        return "test";
    } 
}
Run Code Online (Sandbox Code Playgroud)

之前我问了一个类似的问题:.net 4 xslt转换扩展功能坏了.对于模糊的调用,答案是对的,但即使使用另一个正确的对象,它也无法正常工作.我没有收到任何错误,只是没有显示数据.

我也试过这个;

static void test() {
    // Create the XslCompiledTransform and load the …
Run Code Online (Sandbox Code Playgroud)

c# xslt asp.net-4.0 extension-objects

3
推荐指数
1
解决办法
2239
查看次数

标签 统计

asp.net-4.0 ×1

c# ×1

extension-objects ×1

xslt ×1