我想做的是,从(.Net)XSLT 转换内部,我将调用一个模板,该模板将返回一些 XML,但返回的 XML 本身可能包含要处理的 XSLT 指令。这个过程应该递归地运行,直到没有 XSLT 剩下,然后输出将被放入结果树中。
可能每个"template"实际上必须是一个单独的文件,但我希望在整个过程中维护上下文(参数、变量和上下文节点等),因此只需递归调用 Transform( ) 方法似乎还不够。
一个有点相关的问题:假设我从模板内部调用扩展函数。有没有办法从扩展函数内部调用模板?扩展对象的文档似乎非常简单——它告诉您如何调用它,但没有记录我可以与之交互的 xslt 基础结构的任何部分。
很抱歉没有提供一个像样的具体例子,但我目前处于研究阶段,所以这一切都有点抽象。
安迪
最佳答案
如果转换的结果在 http://www.w3.org/1999/XSL/Transform
中有节点命名空间,那么您将动态生成 XSLT,并且要执行生成的 XSLT,您需要启动/调用新的转换,它不能从 XSLT 完成(至少在没有扩展功能的情况下不能)。
It may be that each "template" actually has to be a separate file, but I'd like to have the context (parameters, variables, and context nodes etc) maintained throughout the whole process, so just having recursive invocations of the Transform() method seems like it will not suffice.
您经常谈论模板,但 XSLT 使用模块进行操作,模板只是模块可以拥有的声明类型之一。为什么要维护参数、变量和上下文节点?转换完成后,不再需要此信息。
A somewhat related question: say I call an extension function from inside a template. Is there a way to invoke a template from inside the extension function?
不,您不能从扩展函数调用模板。
关于.net - .Net 中的递归/反射 XSLT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6331875/