Xslt 如何从集合中获取文件的绝对文档路径

Xslt 如何从集合中获取文件的绝对文档路径,xslt,xslt-2.0,Xslt,Xslt 2.0,请建议获取通过xslt集合收集的每个文档的绝对路径 Posted script能够提供所需的绝对路径,但我使用了两个集合(可能需要不必要的内存来存储所有文章的信息两次,一个集合用于收集信息,另一个集合用于收集document-uri()s) XMLs: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-

请建议获取通过xslt集合收集的每个文档的绝对路径

Posted script能够提供所需的绝对路径,但我使用了两个集合(可能需要不必要的内存来存储所有文章的信息两次,一个集合用于收集信息,另一个集合用于收集
document-uri()
s)

XMLs:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:variable name="varDocuments">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]"/>
</xsl:variable>

<xsl:variable name="varDocuments1">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]/document-uri(.)"/>
</xsl:variable>

<xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="/">
    <Table border="1">
        <TR><TH>Position</TH><TH>Title</TH><TH>Tag1</TH><TH>Tag2</TH><TH>Tag3</TH><TH>Tag4</TH><TH>Path</TH></TR>
        <xsl:for-each  select="$varDocuments">
            <xsl:for-each select="article">
                <TR>
                    <xsl:variable name="varPos" select="position()"/>
                    <td><xsl:value-of select="position()"/></td>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="count(descendant::tag1)"/></td>
                    <td><xsl:value-of select="count(descendant::tag2)"/></td>
                    <td><xsl:value-of select="count(descendant::tag3)"/></td>
                    <td><xsl:value-of select="count(descendant::tag4)"/></td>
                    <td><xsl:value-of select="normalize-space(tokenize($varDocuments1, 'file:/')[position()=$varPos + 1])"/></td>
                </TR>
            </xsl:for-each>
        </xsl:for-each>
    </Table>
</xsl:template>

</xsl:stylesheet>
D:/DocumentPath/Project-01/2016/ABC/Test.xml

<article>
  <title>First article</title>
  <tag1>The tag 1</tag1>
  <tag3>The tag 3</tag3>
</article>

第一篇文章
标签1
标签3
D:/DocumentPath/Project-01/2016/DEF/Test.xml

<article>
  <title>Second article</title>
  <tag2>The tag 2</tag2>
  <tag3>The tag 3</tag3>
</article>

第二条
标签2
标签3
和其他XML

XSLT2.0:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:variable name="varDocuments">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]"/>
</xsl:variable>

<xsl:variable name="varDocuments1">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]/document-uri(.)"/>
</xsl:variable>

<xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="/">
    <Table border="1">
        <TR><TH>Position</TH><TH>Title</TH><TH>Tag1</TH><TH>Tag2</TH><TH>Tag3</TH><TH>Tag4</TH><TH>Path</TH></TR>
        <xsl:for-each  select="$varDocuments">
            <xsl:for-each select="article">
                <TR>
                    <xsl:variable name="varPos" select="position()"/>
                    <td><xsl:value-of select="position()"/></td>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="count(descendant::tag1)"/></td>
                    <td><xsl:value-of select="count(descendant::tag2)"/></td>
                    <td><xsl:value-of select="count(descendant::tag3)"/></td>
                    <td><xsl:value-of select="count(descendant::tag4)"/></td>
                    <td><xsl:value-of select="normalize-space(tokenize($varDocuments1, 'file:/')[position()=$varPos + 1])"/></td>
                </TR>
            </xsl:for-each>
        </xsl:for-each>
    </Table>
</xsl:template>

</xsl:stylesheet>

位置标题TAG1TAG2TAG3TAG4路径
所需结果:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:variable name="varDocuments">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]"/>
</xsl:variable>

<xsl:variable name="varDocuments1">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]/document-uri(.)"/>
</xsl:variable>

<xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="/">
    <Table border="1">
        <TR><TH>Position</TH><TH>Title</TH><TH>Tag1</TH><TH>Tag2</TH><TH>Tag3</TH><TH>Tag4</TH><TH>Path</TH></TR>
        <xsl:for-each  select="$varDocuments">
            <xsl:for-each select="article">
                <TR>
                    <xsl:variable name="varPos" select="position()"/>
                    <td><xsl:value-of select="position()"/></td>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="count(descendant::tag1)"/></td>
                    <td><xsl:value-of select="count(descendant::tag2)"/></td>
                    <td><xsl:value-of select="count(descendant::tag3)"/></td>
                    <td><xsl:value-of select="count(descendant::tag4)"/></td>
                    <td><xsl:value-of select="normalize-space(tokenize($varDocuments1, 'file:/')[position()=$varPos + 1])"/></td>
                </TR>
            </xsl:for-each>
        </xsl:for-each>
    </Table>
</xsl:template>

</xsl:stylesheet>

位置
标题
Tag1
Tag2
Tag3
标签4
路径
1.
第一篇文章
1.
0
1.
0
D:/DocumentPath/Project-01/2016/ABC/Test.xml
2.
第二条
0
1.
1.
0
D:/DocumentPath/Project-01/2016/DEF/Test.xml
3.
第三条
1.
0
0
2.
D:/DocumentPath/Project-01/2016/GHI/Test.xml

我首先建议更改

<xsl:variable name="varDocuments">
    <xsl:copy-of select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]"/>
</xsl:variable>

至少

<xsl:variable name="varDocuments" select="collection('file:///D:/DocumentPath/Project-01/2016/?select=*.xml;recurse=yes')
        [matches(document-uri(.), '2016/([A-z]+)/.*?.xml')]"/>

因为似乎不需要使用
集合
拉入文档,然后使用
副本
创建附加副本


通过此更正,当您使用
处理每个文档时,您现在只需在那里读取
文档uri(.)
,因为您正在处理拉入的文档,而不是组装的任何副本。

谢谢您的完美建议,先生,获得了所需的绝对路径,再加上一条。