Lokesh
Lokesh

Reputation: 129

XSLT to read xml content from a text file with no xml declaration or .xml file extension

I am using named template and collection function of XSLT2.0 to feed a bunch of files for processing. These set of input files have the naming format like 'a.b.c.d' and have xml content, but neither with proper file extension like ".xml" nor contain xml declaration in the file content.

Thus the below error is thrown by Saxon XSLT processor

Type error XPTY0004: Required item type of result of call to collection is node(); supplied value has item type xs:base64Binary Required item type of result of call to collection is node(); supplied value has item type xs:base64Binary`

When I change the file name extension to ".xml" or include xml declaration <?xml version="1.0" ?> in the input files, there is no such error and the processing is fine.

Is there a way to force collection function to treat all the input files as xml files by default? The syntax of collection function doesn't seems to have an attribute to specify content type.

Upvotes: 1

Views: 216

Answers (1)

Michael Kay
Michael Kay

Reputation: 163312

The CollectionFinder mechanism in Saxon is highly configurable, so it's not so much a question of whether you can do it, as what's the simplest way to do it.

I think it should be possible simply to add "?content-type=application/xml" to the end of the collection URI.

Or if you prefer to do it from the API, I think configuration.registerFileExtension("", "application/xml") should do the job.

Upvotes: 1

Related Questions