2014-07-15 15 views
1

请建议XSLT中的'Collection'函数从'main.xml'中从子目录名称中获取信息,名称以9000系列开头,即 D:/Author-Index/9001/main.xml,D:/Author-Index/9002/main.xml,D:/Author-Index/9003/main.xml,D:/ Author-Index/9009/main。 xml,D:/Author-Index/90nn/main.xml(第n个数字)XSLT:使用xslt从名称9000系列的所有文件夹中收集xml文件Collection

但不是从D:/Author-Index/939/main.xml(因为三位数字文件夹)。

我正在使用collection('file:///D:/AuthorIndex/9[0-9][0-9][0-9]?select=*main.xml;recurse=yes')找到文件夹名称错误始于9[n][n][n]/main.xml

XML1:d:/Author-Index/9001/main.xml

 <article> 
    <fm> 
    <title>Journey to Galaxy</title> 
    <author><snm>Kishan</snm><fnm>TR</fnm></author> 
    </fm> 
    <body> 
     <p>This article explian about Galaxy Journey</p> 
    </body> 
</article> 

XML2:d:/作者指数/9002/main.xml

<article> 
    <fm> 
    <title>Journey to Mars</title> 
    <author><snm>Rudramuni</snm><fnm>TP</fnm></author> 
    </fm> 
    <body> 
    <p>This article explian about Mars Journey</p> 
    </body> 
</article> 

XSLT:XSLT版本2

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 
    <xsl:variable name="varCollection"> 
     <xsl:copy-of select="collection('file:///D:/AuthorIndex/9[0-9][0-9][0-9]?select=*main.xml;recurse=yes')"/> 
    </xsl:variable> 
    <xsl:template match="root"> 
    <xsl:for-each select="$varCollection//article"> 
     <xsl:element name="title1"><xsl:value-of select="//fm//title"/></xsl:element> 
     <xsl:element name="aug"> 
      <xsl:for-each select="//fm//author"> 
       <xsl:element name="au"><xsl:element name="snm"><xsl:value-of select="snm"/></xsl:element><xsl:text> </xsl:text> 
         <xsl:element name="fnm"><xsl:value-of select="fnm"/></xsl:element> 
       </xsl:element> 
      </xsl:for-each> 
     </xsl:element> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

所需的结果:

<article> 
    <aug> 
    <au><snm>Kishan</snm><fnm>TR</fnm></au> 
    <title1>Journey to Galaxy</title1> 
    <au><snm>Rudramuni</snm><fnm>TP</fnm></au> 
    <title1>Journey to Mars</title1> 
    </aug> 
</article> 

回答

3

这是不是很有效,但你可以使用collection()功能循环扫描所有D:/AuthorIndex文件夹*main.xml文件,然后使用谓词过滤器仅选择在9000个系列文件夹中的文件:

<xsl:variable name="varCollection"> 
    <xsl:copy-of 
     select="collection('file:///D:/AuthorIndex/?select=*main.xml;recurse=yes') 
     [matches(document-uri(.),'AuthorIndex/9[0-9][0-9][0-9]/.*?main.xml')]"/> 
</xsl:variable> 
1

了由collection()函数接受的URI的形式从产品而异。您使用的是首次在Saxon中引入的格式,并随后被其他一些产品采用。然而,撒克逊的实现当然不允许集合URI成为这样的正则表达式,如果其他实现能够做到,我会感到惊讶。

答案将是具体产品。在撒克逊,你可以编写你自己的CollectionURIResolver来处理这种形式的集合URI。

+0

@Mads Hansen先生,非常感谢您的建议。它按要求完美地工作。 –