如何加快跨文件夹从多个 XML 中获取数据的过程

How to speed-up the data fetching process from multiple XMLs across folders

请建议如何加快仅从选定文件夹中获取所需数据的过程。

目前的编码正在检查所有“tx1.xml”的提取,其中存在数千个 tx1.xml。我们需要从 'Journals.txt' 文件中提到的 'JOURNALs' 中获取。

文件夹结构:

D:\Rudramuni\XSLTPrograms\FilesFetch\Files\AJN56\Over\tx1.xml
D:\Rudramuni\XSLTPrograms\FilesFetch\Files\AJN57\Over\tx1.xml
D:\Rudramuni\XSLTPrograms\FilesFetch\Files\EB54\Over\tx1.xml
D:\Rudramuni\XSLTPrograms\FilesFetch\Files\CLS34\Over\tx1.xml <!--Not required because not mentioned in 'Journal.txt'-->

Path.txt

<path>
<a>D:\Rudramuni\XSLTPrograms\FilesFetch\Files</a>
</path>

Journals.txt

<root>
AJN
EB
</root>

输入XML (..\AJN57\Over\tx1.xml):

<article>
<fm>
    <title>Article One</title>
    <aug><au><fnm>Rudramuni</fnm><snm>TP</snm></au></aug>
</fm>
 </article>

在上面的文件中,脚本只需要找到三个'tx1.xml,因为在'Journal.txt' AJNEB 只提到过。

XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:variable name="varFile" select="document('Path.txt')"/><!--Path of files which given in Path.txt-->
<xsl:variable name="varPath" select="translate($varFile/path/a, '\', '/')"/>

<xsl:variable name="varFile1" select="document('Journals.txt')"/><!--Text file is having Journals name for fetching information-->
<xsl:variable name="varJs"><!--each line of txt file will get tag 'a' -->
    <xsl:for-each select="$varFile1/root/text()">
        <xsl:for-each select="tokenize(., '\n')[normalize-space()]">
            <a><xsl:sequence select="normalize-space()"/></a>
        </xsl:for-each>
    </xsl:for-each>
</xsl:variable>

<xsl:variable name="str1" select="concat('file:///', $varPath,'/?select=tx1.xml;recurse=yes;on-error=ignore')"/>

<xsl:variable name="varFinal">
    <xsl:for-each select="$varJs/a">
        <xsl:variable name="varJName" select="."/>
        <xsl:variable name="varCollection">
            <xsl:copy-of select="collection($str1)
                [matches(document-uri(.), $varJName) and matches(document-uri(.), '[0-9][0-9][0-9][0-9]/Over/tx1.xml')]"/>
        </xsl:variable>
        <fnm><xsl:value-of select="$varCollection//*:fnm"/></fnm><xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:variable>

<xsl:template match="root">
    <xsl:value-of select="$varFinal"/>
</xsl:template>
</xsl:stylesheet>

需要输出

Rudramuni Kishan
Likhith

XSLT 处理器: Saxon9he

查看您的样式表,您似乎正在加载 D:\Rudramuni\XSLTPrograms\FilesFetch\Files 下的所有 tx1.xml 个文件,但您想要的只是那些与此路径相关的文件,但在 [=43] 中提到=].

与其创建全局变量以供 collection 函数加载,不如将其更改为循环或在 "journals.txt" 的已解析变量上使用应用模板,即 $varJs .您已经在 $varFinal.

中开始这样做了

改变这个:

<xsl:copy-of select="collection($str1)
     [matches(document-uri(.), $varJName) 
     and matches(document-uri(.), '[0-9][0-9][0-9][0-9]/Over/tx1.xml')]"/>

对此:

<xsl:copy-of select="collection(f:get-path($varPath, .))" />

添加以下全局变量(并删除 $str1):

<xsl:variable name="collection-query" 
    select="'?select=tx1.xml;recurse=yes;on-error=ignore'"/>

添加以下函数:

<xsl:function name="f:get-path" as="xs:string">
    <xsl:param name="base" as="xs:string" />
    <xsl:param name="segment" as="xs:string" />
    <xsl:sequence select="concat('file:///', $base, '/', $segment, '/', $collection-query)" />
</xsl:function>

删除以下行:

<xsl:variable name="varJName" select="."/>

请注意,我没有对此进行测试,因为它需要我设置一个完整的目录结构,但按照这些思路进行一些操作是可行的。此外,在函数中创建 URI 可以更轻松地修复它,使其更接近您的要求。

由于您已经对集合 uri 中的 tx1.xml 进行了预选,现在您的选择仅基于 "journals.txt" 中您实际需要的文件,因此似乎xsl:copy-of 语句中的原始代码中不需要谓词。