我目前正在开发一个涉及大量XSLT转换的项目,我真的需要一个调试器(我有1000多行的XSLT ,我没有写它们:-).
该项目是用C#编写的,并使用扩展对象:
xslArg.AddExtensionObject("urn:<obj>", new <Obj>());
Run Code Online (Sandbox Code Playgroud)
据我所知,在这种情况下,Visual Studio是唯一可以帮助我逐步调试转换的工具.由于扩展对象,静态调试器没有用处(当它到达引用其命名空间的元素时会抛出错误).幸运的是,我发现这个线程给了我一个起点(至少我知道它可以完成).
在搜索MSDN之后,我找到了可以进入转换的标准.它们列在这里.简而言之:
IXmlLineInfo接口(XmlReader&co.)的类加载XML和XSLTXSLTCompiledTransform构造函数中使用的XML解析器是基于文件的(XmlUriResolver应该可以工作).据我所知,我符合所有这些标准,但它仍然无效.相关代码示例发布如下:
// [...]
xslTransform = new XslCompiledTransform(true);
xslTransform.Load(XmlReader.Create(new StringReader(contents)), null, new BaseUriXmlResolver(xslLocalPath));
// [...]
// I already had the xml loaded in an xmlDocument
// so I have to convert to an XmlReader
XmlTextReader r = new XmlTextReader(new StringReader(xmlDoc.OuterXml));
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddExtensionObject("urn:[...]", new [...]());
xslTransform.Transform(r, xslArg, context.Response.Output);
Run Code Online (Sandbox Code Playgroud)
我真的不明白我做错了什么.我检查了两个XmlReader对象上的接口,然后实现了所需的接口.此外,BaseUriXmlResolver继承自 …
你能解释一下这个扩展对象模式吗 and how it differ from the Adapter Pattern?
网络中似乎只有很少的资源可以解释扩展对象模式,而且大多数资源都有些令人困惑(至少对我而言)。
提前致谢。
我正在升级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)