2016-11-10 31 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