在XSLT中,如何获取XML文件的文件创建/修改日期?
我想知道我的 XSLT 代码当前正在处理的 XML 文件的文件创建/修改日期。
我正在处理 XML 文件并生成 HTML 报告。 我想在 HTML 报告中包含源 XML 文件的日期。
注意:我使用 C# .NET 2008 并使用内置的 XslCompiledTransform 类。 此后,我使用此处其他答案的输入找到了解决方案(单独的答案)。 谢谢!
I would like to know the file creation/modification date of the XML file currently being processed by my XSLT code.
I am processing an XML file and producing an HTML report. I'd like to include the date of the source XML file in the HTML report.
Note: I am using C# .NET 2008 and using the built-in XslCompiledTransform class. I have since found a solution (separate answer) using input from other answers here. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建/修改日期必须写入 XML 文件中,否则您无法找到它,除非您以某种方式与文件系统进行通信。
这个问题有些相关:xslt-how-to-get-file-names-from-a-certain-directory
The creation/modification date must be written into the XML file, otherwise you cannot find it out, unless you communicate somehow with the filesystem.
This question is somewhat related: xslt-how-to-get-file-names-from-a-certain-directory
XSLT 唯一可以访问的是源树的节点、通过
document()
函数读取的文档中的节点、XSLT 模板本身中的节点(同样通过document()
函数),以及作为参数传递到转换的值。因此,如果您希望文件名及其创建/修改日期可用于您的转换,则必须将它们放在这些位置之一。
可以实现 XSLT 扩展方法来执行此操作,具体取决于您使用的平台,但这将是我的最后选择。
The only things that XSLT has access to are nodes of the source tree, nodes in documents read in via the
document()
function, nodes in the XSLT template itself (again via thedocument()
function), and values passed in to the transform as arguments.So if you want the filename and its creation/modification date to be available to your transform, you have to put them in one of those places.
It's possible to implement XSLT extension methods to do this, depending on what platform you're using, but that would be my last choice.
经过 Kaarel 和 Robert 的建议,我得到了以下解决方案:
在 C# 中获取文件修改日期并将其传递给 XSLT 处理器,如下所示:
然后在 XSLT 代码中,定义并访问该参数作为参数,如下所示:
After suggestions from Kaarel and Robert, I was able to reach the following solution:
Get the file modification date in C# and pass it to the XSLT processor as follows:
Then in the XSLT code, define and access that argument as a param as follows: