Project

Profile

Help

Should uri-collection work with non XML files?

Added by Martin Honnen over 9 years ago

Based on the answer in http://stackoverflow.com/questions/28724061/generating-a-document-with-list-of-files-in-a-directory-using-xslt-2-0 and also based on the text

It allows resources to be retrieved that are not well-formed XML documents: for example, the returned URIs might be referenced using the fn:unparsed-text function rather than the fn:doc function.

in the description of the @uri-collection@ function in http://www.w3.org/TR/xpath-functions-30/#func-uri-collection I thought that it allows to find URIs of non XML files, like plain text @.txt@ files or even binary files.

However when I try the code



{
let $input := uri-collection('.?select=*.txt')
for $i in $input
return
    
      {tokenize($i, '/')[last()]}
    
}

with Saxon 9.6 HE in a directory containing a @.txt@ file I get an error message saying

Error on line 1 column 1 of test1.txt: SXXP0003: Error reported by XML parser: Content ist nicht zulässig in Prolog. Query failed with dynamic error: org.xml.sax.SAXParseException; systemId: file:/C:/Users/Martin%20Honnen/Documents/xslt/test-uri-collection/test1.txt; lineNumber: 1; columnNumber: 1; Content ist nicht zulässig in Prolog.

which seems to indicate that the function tried to parse the file as XML and the function can't return URIs of non XML files.

Is there a way to use that function to find non XML files like plain text files?


Replies (1)

RE: Should uri-collection work with non XML files? - Added by Martin Honnen over 9 years ago

It took me a while to figure out what was missing to select non XML plain text files but adding @unparsed=yes@ as in @let $input := uri-collection('.?select=*.txt;unparsed=yes')@ solved it.

    (1-1/1)

    Please register to reply