在XSLT中有一个函数可以接受一个目录路径,并将其中的所有文件都返回?
我有一个xml文件,现在这样读取
< filelist> < file> fileA.xml< / file> < file> fileB.xml< / file> < / filelist>现在有一个名为 dir 的目录,文件 fileX.xml , fileY.xml 以及其他一些xml文件。我想将这些文件添加到原始XML文件中,以便我可以得到:
< filelist> < file> fileA.xml< / file> < file> fileB.xml< / file> < file> fileX.xml< / file> < file> fileY.xml< / file> ....<! - 其他文件 - > < / filelist>是否有XSLT方法来执行此操作?东西,需要在一个目录根,并能够通过它的所有文件迭代?然后我可以调用类似于:
< xsl:element name = file> < xsl:copy> <! - 任何文件名称 - > < XSL:复制和GT; < / xsl:element> 0[Edit-solution]
所有的答案都非常有帮助。我最终找到了一个外部解决方案(使用撒克逊)。我认为可能有助于其他人在这里发表我的解决方案,虽然这是非常具体的我自己的情况。
我使用Ant来构建一个java web应用程序,并且在部署之前需要转换一些xml文件。因此,我使用 xslt 任务通过在类路径中添加saxon9.jar来完成这项工作。在我的xsl文件中,我只是做了这样的事情:
< xsl:for-each select =collection(' ../dir/?select=*.xml')> < xsl:element name ='file'>XSLT没有内置任务。 XSLT是一种转换语言 - 对于动态输出,您通常需要一个包含所有东西的转换 source (只是以不同的形式)–你不能从空中创建XML。
解决这个问题的三种方法是: $ b $ ol
归结为:
- 您需要外部编程语言的帮助
- 您绝对不需要 em> XSLT完成任务,因为XML输出是您所需要的,不需要任何转换。
错误:不要使用XSL为此。
Is there a function in XSLT that can takes in a directory path and gives back all the files in it??
I have a xml file now reads like this
<filelist> <file>fileA.xml</file> <file>fileB.xml</file> </filelist>Now, there's directory called dir, has files fileX.xml, fileY.xml and a bunch of other xml files in it. I want to add these files on to the orginal xml file, so that I can get:
<filelist> <file>fileA.xml</file> <file>fileB.xml</file> <file>fileX.xml</file> <file>fileY.xml</file> .... <!-- other files --> </filelist>Is there an XSLT way to do this?? something that takes in a dir root, and is able to iterator through all of the files in it?? And then I could just call something like:
<xsl:element name = file > <xsl:copy> <!--whatever file name--> <xsl:copy> </xsl:element>0[Edit-solution]
all of the answers were very helpful. I ended up finding an external solution (using saxon). I thought it may be helpful for other people to post my solution here, although it is very specific to my own situation.
I use Ant to build a java web app and need to translate some xml files before deployment. Hence, I was using the xslt task to do the job by adding the "saxon9.jar" in the classpath. And in my xsl file, I just did something like this:
<xsl:for-each select="collection('../dir/?select=*.xml')" > <xsl:element name='file'> <xsl:value-of select="tokenize(document-uri(.), '/')[last()]"/> </xsl:element> </xsl:for-each>解决方案
XSLT has nothing built-in for this task. XSLT is a transformation language - for dynamic output you generally need a transformation source that contains everything already (just in a different form) – you cannot create XML from nothing.
The three ways you can tackle the problem are:
It boils down to this:
- You will need help from an external programming language
- You do not absolutely need XSLT do accomplish the task, since XML output is all you need and no transformation is required.
Ergo: Don't use XSL for this.
更多推荐
XSLT:如何从某个目录获取文件名?
发布评论