2016-11-10 56 views
0

我在使用Saxon中的collection()函数时遇到了困难。我想根据目录中的所有XML文件生成文本报告。我创建了一个命名模板,我将它从命令行传递给样式表。我能够输出带有标题的文本文件,但似乎XPATH表达式并未拾取单个元素。XPATH表达式和Saxon集合()函数

这里是XML:

<?xml version='1.0'?> 
<document form='Submission'> 
    <item name='FiscalYear'><text>2012</text></item> 
    <item name='RequestType'><text>General</text></item> 
    <item name='LeadMinistry'><text>Ministry of Truth</text></item> 
    <item name='MinRef'><text>67890</text></item> 
    <item name='LogNo'><text>12345</text></item> 
    <item name='Division'><text>IFSB</text></item> 
    <item name='Branch'><text>MEI</text></item> 
</document> 

这里是XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text" omit-xml-declaration="yes" indent="no"/> 
    <xsl:variable name="newline"> 
     <xsl:text> 
</xsl:text> 
    </xsl:variable> 
    <xsl:param name="input-dir" select="'file:///C:\path\to\XML\input\files\'"/> 
    <xsl:template name="main"> 
     <xsl:variable name="input-docs" select="collection(iri-to-uri(concat($input-dir, '?select=*.xml')))"/> 
     <xsl:value-of select="'LogNo|MinRef|FiscalYear|RequestType|Division|Branch|LeadMinistry'"/> 
     <xsl:value-of select="$newline"/> 
     <xsl:for-each select="$input-docs/document[@form = 'Submission']"> 
      <xsl:value-of select="concat(item[@name = 'LogNo']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'MinRef']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'FiscalYear']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'RequestType']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'Division']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'Branch']/text, '| ')"/> 
      <xsl:value-of select="concat(item[@name = 'LeadMinistry']/text, '| ')"/> 
      <xsl:value-of select="$newline"/> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

回答

0

一个URI使用所有斜杠所以更改file:///C:\path\to\XML\input\files\file:///C:/path/to/XML/input/files

+0

我将斜线改为正斜杠,但仍不起作用。我认为斜线不是问题所在 - 实际上,我将这个XSLT的基础与我几年前写的类似,我在其中混合了向前和向后的斜杠。 – b00kgrrl

+0

我在目录路径中发现一个错误,但感谢您指出混合斜线。 – b00kgrrl